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
PHP

Avatar of undefined
Last Comment
Zakaria Acharki
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
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.
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo