souce code souce code - 1 year ago 59
PHP Question

how to add a string value into php array

When i add a string value into array through

, it give me a numeric value i.e

foreach($array as $value){
$push=array_push($array2, $value);

It output is
.what i want to is
$array2 = array("test","test2","one")

Answer Source

The array_push is working as it is designed for.

It will add the value and returns the number of elements in that array.

so it is natural if it is returning 3 your array has 2 elements after array push there are now three elements.

You should print_r($array2) your array and look the elements.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download