Reputation: 16224
I need to convert a PHP $var
to a array.
I did like this
$array = array();
$var = $array;
but this way the doesn't give the output as this
Array ( [0] => [1] => 9 [2] => 7 [3] => 11 [4] => 5 )
It gives the value like a normal variable, it prints 154515100
.
Upvotes: -1
Views: 2453
Reputation: 21563
What is the variable to begin with?
If it was an object, you could cast it to an array like
$var=(array)$var;
It sounds like you want to convert from a string or an integer to an array, though. Please provide more details.
Upvotes: 3
Reputation: 3060
It depends on what the variable is. If it is a string, do: $array = str_split($var);
Upvotes: 3