This is not an array inside another:
books => "book1", "book2"
To be an array would have to be like this (ps: put quotation marks around the keys too):
$array = array(
"user" => "user1",
"name" => "name1",
"books" => array( "book1", "book2" )
);
Or in php5.4 +:
$array = [
"user" => "user1",
"name" => "name1",
"books" => [ "book1", "book2" ]
];
Otherwise 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"
);
Aliais array['books'].length
does not work in PHP, ie javascript probably does not work inside PHP.
See the example online working: link
The check 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';
}