oyshee oyshee - 2 months ago 8
PHP Question

Unexpected syntax error on "for" looping with json array

I'm trying to looping a json array on php. But unexpectedly it showing


Parse error: syntax error, unexpected '=', expecting ';' in /home/windsys/public_html/siddiqa/function/ordermedicine.php on line 13


I'm not sure why it's showing syntax error on line 13. I've checked carefully. Please tell me where is the wrong.

<?php
require_once('../configuration.php');
$con=new mysqli($hostname,$dbusername,$dbpass,$dbname);
if (mysqli_connect_errno($con)) {
die('The connection to the database could not be established.');
}
$obj = $_POST['data'];
//print_r($obj);
//echo $_POST['medicine_name'];
echo $obj[0]['medicine_name'];
$objcount=count($obj);
echo count($obj);
for(i=0;i<count($obj);i++){
echo $obj[i]['medicine_name'];

}

?>

Answer

change

for(i=0;i<count($obj);i++){
  echo $obj[i]['medicine_name'];
}

to

for($i=0;$i<count($obj);$i++){
  echo $obj[$i]['medicine_name'];
}

ypu are working with php variable so define every vars with $