PHP Questions

  1. What is Singleton Pattern?
  • Answer:
  • Singleton Pattern - is a design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. The concept is sometimes generalized to systems that operate more efficiently when only one object exists, or that restrict the instantiation to a certain number of objects.

Added By : Sanjay

  1. What is the difference between Split and Explode?
  • Answer:
  • Both the functions are used to Split a string. However,

    Difference is:-

    Split - Splits string into array by regular expression.

    Explode - Split a string by string.

    Description:

    Split is used to split a string using a regular expression. On the other hand, Explode is used to split a string using another string.
    <?php
    // Delimiters may be slash, dot, or hyphen
    $date = "04/30/1973";
    list($month, $day, $year) = split('[/.-]', $date);
    echo "Month: $month; Day: $day; Year: $year";
    ?>
    
    <?php
    // Delimiters is /
    $date = "04/30/1973";
    list($month, $day, $year) = explode('/', $date);
    echo "Month: $month; Day: $day; Year: $year";
    ?>
    

    For Example:

    explode(" and ", "Hello and World and Program");

    split(" : ", "Hello : World : Program");

    Both of these functions will return an array that contains Hello, World, and Program.

Added By : Praveen Kumar


  1. How can we retrieve the data in the result set of MySQL using PHP?
  • Answer:
  • You can do it by 4 Ways

      1. mysql_fetch_row

      2. mysql_fetch_array

      3. mysql_fetch_assoc

      4. mysql_fetch_object

Added By : Jagdish Gupta

Post Your Question
Social Sharing
Search