In PHP how would I push the values of an array on to the end of itself -


I have an array:

  $ myArray = array ("foo", "bar");  

What is a good way to repeat the values ​​at the end of the array so that:

  $ myArray = array ("foo", "bar", "Foo", "bar");  

I thought maybe array_push would work like this:

  array_push ($ myArray, $ myArray);  

But it actually pushes the array object and not the value of the array.

You can do this array_merge

 < Code> $ tmp = $ myArray; $ MyArray = array_merge ($ myArray, $ tmp);  

It will depend on you not to worry about array keys.

Another solution would be:

  $ tmp = $ myArray; Forex Currency ($ TMP $ Val) {$ myArray [] = $ val; }  

Comments