0

I have a variable $object like this :

$object = ['Apple-2','Apolo-23','Nine-99','Ex-0'];

How do to make each value in $object to array. I want output like this:

Array
(
    [0] => Apple-2,
    [1] => Apolo-23,
    [2] => Nine-99,
    [3] => Ex-0
)
Rahmat Effendi
  • 337
  • 2
  • 11
  • 29

2 Answers2

3

$object is already an array. You just need to print it.

echo '<pre>'; 
print_r($object);
echo '</pre>';

Output :

enter image description here

if need comma after each value, add below line before print:

array_walk($object, function(&$object) {
    $object = $object . ",";
    return $object;
});
Amol
  • 343
  • 2
  • 19
1

You can use json_decode:

json_decode(str_replace("'", '"', $object));
slince
  • 21
  • 2