1

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.

0

2 Answers 2

1

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++;
}
Sign up to request clarification or add additional context in comments.

Comments

1

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'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.