This is not an array within another:
books => "book1", "book2"
For it to be an array it would have to be like this (ps: put quotes on keys as well):
$array = array(
"user" => "user1",
"name" => "name1",
"books" => array( "book1", "book2" )
);
Or in php5.4+:
$array = [
"user" => "user1",
"name" => "name1",
"books" => [ "book1", "book2" ]
];
The other way you did:
$array = array(
user => "user1",
name => "name1",
books => "book1", "book2"
);
It would be the same as:
$array = array(
"user" => "user1",
"name" => "name1",
"books" => "book1",
0 => "book2"
);
Allies array['books'].length
does not work in PHP, that is javascript probably doesn’t work inside PHP.
See the online example working: https://ideone.com/0vnE3R
The verification in a if
would be:
if (count($array['books']) == 2) {
echo 'Contém 2 elementos';
}
Or:
if (count($array['books']) > 1) {
echo 'Contém 2 ou mais elementos';
}
Dear Sabrina I don’t understand, why did you choose the other answer as correct? She doesn’t show anything like "tell," I won’t interfere with her judgment, but I’d simply like to know where this is the motivation for this and whether it really solved her problem.
– Guilherme Nascimento