PHP - Need help with Array and Explode

2 replies
With a string $string1 = "One Two Three",

I need to create an array like this $desiredarray = ("One Two Three", "One", "Two", "Three")

I can create an array ("One", "Two", "Three"), by $words = explode($string1).

How do I combine $string1 and $words to get $desiredarray?

Thanks.
#array #explode #php
  • Profile picture of the author Arine Mark
    Example #1 array_push() example
    <?php
    $stack
    = array("orange", "banana");
    array_push($stack, "apple", "raspberry");
    print_r($stack);
    ?>


    The above example will output:

    Array
    (
    [0] => orange
    [1] => banana
    [2] => apple
    [3] => raspberry
    )
    {{ DiscussionBoard.errors[357415].message }}
    • Profile picture of the author Khai Lay
      Thank you very much Arine. Much appreciated. Merry Christmas!
      {{ DiscussionBoard.errors[357517].message }}

Trending Topics