سلام
من طبق آموزش برای ایجاد آرایه از json عمل کردم و به ارور برخورد کردم و ممنون میشم راهنماییم کنین
متن ارور
Notice: Trying to get property '0' of non-object in C:\xampp\htdocs\php-expert-basic\05-arrays\array-and-json.php on line 46
Notice: Trying to get property 'name' of non-object in C:\xampp\htdocs\php-expert-basic\05-arrays\array-and-json.php on line 46
Notice: Trying to get property 'firstname' of non-object in C:\xampp\htdocs\php-expert-basic\05-arrays\array-and-json.php on line 46
<?php
$users2 = array(
"0" =>[
"name" =>[
"firstname"=>"ali",
"lastname"=>"bayat",
],
"email" =>"ali@gmail.com",
"username" =>"ali7885",
],
"1" =>[
"name" =>"mohammad",
"email" =>"md@gmail.com",
"username" =>"md8585",
],
"2" =>[
"name" =>"maryam",
"email" =>"maryam@yahoo.com",
"username" =>"maryam8585",
],
);
//print_r($users2);
echo "<br>";
echo "<br>";
//*********************************************** */
//array to json
$jsonstr = json_encode($users2);
//echo $jsonstr;
/************************************************* */
//json to array associative
echo "<br>";
echo "<br>";
$jsonArr =json_decode($jsonstr,1);
print_r($jsonArr);
echo "<br>";
echo "<br>";
echo ($jsonArr[0]["name"]["firstname"]);
echo "<br>";
echo "<br>";
/************************************************** */
// json to stdclass object
$userObject =json_decode($jsonstr);
print_r($jsonArr);
echo "<br><br>";
echo($userObject->{0}->name->firstname);
?>