Reputation: 1209
I am new to php, for my android application I am using php. My problem is I can not able to access the array object value.
Store the select query table value like below
$rows = array();
$i=0;
while($r = mysqli_fetch_assoc($result)) {
$rows[$i] = $r;
$i++;
}
When I display the value using echo json_encode($rows);
it will display [{"CurrentVersion":"0.0.1","ForceUpdate":"1"}]
this value. But when I trying to access this value in php I can not able to access I tried the below methods.
echo $verDetails[0].ForceUpdate; => ArrayForceUpdate <- I got this value
echo $verDetails[0] => Array <- I got this value
echo $verDetails[0]->ForceUpdate;=> Nothing got
I want to get the Forceupdate value = 1. Please help me, I know many one feel this is the cheap question and you will put negative vote, but I don't have other option. I tried in many ways but I am not get any answers.
Upvotes: 1
Views: 34
Reputation: 3467
mysqli_fetch_assoc returns an associative array. So you have to access the values like this:
$verDetails[0]['ForceUpdate']
To use the arrow syntax, use mysqli_fetch_object:
while($r = mysqli_fetch_object($result)) {
$rows[$i] = $r;
$i++;
}
Upvotes: 1
Reputation: 6994
You have multidimensional array try like this..
echo $rows[0]['CurrentVersion'];
echo $rows[0]['ForceUpdate'];
If you have json format data.use json_decode()
to convert it into array.Then access each element.like this
$json = '[{"CurrentVersion":"0.0.1","ForceUpdate":"1"}]';
$rows = json_decode($json,true);
echo $rows[0]['CurrentVersion']."<br/>";
echo $rows[0]['ForceUpdate'];
Upvotes: 1