D
D
Donsov2020-11-22 23:29:56
PHP
Donsov, 2020-11-22 23:29:56

Why does an array with a variable give the wrong result?

$d = ("1, 2, 3");
$array = array($d);
print_r($array);


Why does an array with a variable not work, we get the following result:
Array
(
    [0] => 1, 2, 3
)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
toxa82, 2020-11-22
@toxa82

What do you want to receive? Your array consists of one string with numbers separated by commas. You get an array of arrays.

D
Donsov, 2020-11-22
@Donsov

Then the question is different, how to split the enumeration into lines?
like in this example but with $a variable inside array which contains 1, 2 ,3 ?
$array = array(1, 1, 1, 1,);
print_r($array);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question