Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Php error with an array

I have this code:
$ckd_sels = array();
	$nc = 0;
	for ($i = 0; $i < $ns; $i++) {
		$s = mysqli_fetch_array($ress,MYSQLI_ASSOC);
		$cbnam = $s['pid'] . "-" . $s['ruid'] . "-" . $s['selno'];
		$ck = "ck" . $cbnam;
		echo "ck + cbnam = " . $ck . "<br>";
		echo  "checked = " . $_POST[$ck] . "<br>";
		if ($_POST[$ck] == "on") {
			echo "post-ck = " . $_POST[$ck] . "<br>";
			$ckd_sels[$i] = $ck;
			echo "ckdcells = " . $ckd_sels[$i] . "<br>";
			$nc++;
		}
	}
	echo "ckd_sels array = " . $ckd_sels . "<br>";
	$_SESSION['ckdsels'] = $ckd_sels;

Open in new window


The last part of the output looks like the attached. Something is wrong with my array definition (I think)

Any help?
Array.JPG
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Richard,

You can't show an array using echo with concatenated string, you need to use :

echo $ckd_sels;
//Or
print_r($ckd_sels);

Open in new window


If you want to show the content of an array inline you may need to convert it to string first using implode or json_encode.