Technical interview questions for software engineers — languages, databases, web, cloud, DevOps, and fundamentals. Browse all topics.

  • PHP Interview Questions

  • OOP Interview Questions

  • jQuery Interview Questions

  • MySQL Interview Questions

  • JavaScript Interview Questions

  • HR Interview Questions

  • HTML Interview Questions

  • C/C++ Interview Questions

  • Showing posts with label array. Show all posts
    Showing posts with label array. Show all posts

    PHP implode() Function


    PHP implode() Function


    implode : The implode() function returns a string from the elements of an array.


    Syntax
    implode(separator,array)


    Example: implode() 


    <?php
    $arr = array("PHP","implode","explode" ,"string","functions");
    $str = implode(",", $arr);
    echo $str; 
    ?>


    Output: PHP, implode, explode, string, functions.


    Bookmark and Share

    PHP explode() Function


    PHP explode() Function


    explode :- The explode() function split a string into an array.

    Syntax
    explode(separator,string)


    Note: Separator cannot be an empty string

    Example: explode()

    <?php


    $name= "PHP implode explode string functions";
    $arr = (" ", $name);
    print_r($arr);
    ?>


    Output:
    array([0]=>"PHP",[1]=>"implode",[2]=>"explode",[3]=>"string",[4]=>"functions");


    Bookmark and Share

    Difference between in_array() and array_search() in php?

    Difference between in_array() and array_search() in php?
    In this tutorial,we will study difference between in_array and array_search.

    in_array : -Checks if a value exists in an array
    array_search() :-searches an array for a given value and returns the  corresponding key if successful.

    in_array Syntax:
    in_array(search value, array , strict Boolean);
    search value:- will be the value to search in an array
    array: will the array to search
    strict Boolean: is optional.

    Example:

    <?php
    $name = array("Rajesh", "Sharma", "PHP", "Linux");
    if (in_array("Rajesh", $name)) 
    {
        echo "Yes";
    }
    else
    {
    echo "False";
    }
    ?>

    Output: Yes

    array_search() :-searches an array for a given value and returns the  corresponding key if successful.

    Syntax:
    array_search()(search value, array , strict Boolean);
    search value:- will be the value to search in an array
    array: will the array to search
    strict Boolean: is optional.

    Example:

    <?php
    $name = array(0=>"Rajesh", 1=>"Sharma", 2=>"PHP", 3=>"Linux");
    echo $key = array_search("Rajesh", $name);

    ?>
    Output: 0


    Bookmark and Share