RE: [PHP] Silly varible question

From: Date: Thu, 13 Jul 2006 14:18:01 +0000
Subject: RE: [PHP] Silly varible question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-239415@lists.php.net to get a copy of this message
> Just make $item a 2-dimensional array, with the first diemnsion addressed by $count; so: > > $item[$count][] = $_POST['phone']; > $item[$count][] = $_POST['category']; > $item[$count][] = $_POST['copy']; > $item[$count][] = $_POST['pic_style']; > $item[$count][] = $cost; > $item[$count][] = $image; > > $count += 1; > > $item[$count][] = ...; > $item[$count][] = ...; > // etc. > > Incorporating the (good) advice to use $_SESSION, this becomes: > > $_SESSION['item'][$count][] = $_POST['phone']; > $_SESSION['item'][$count][] = $_POST['category']; > $_SESSION['item'][$count][] = $_POST['copy']; > $_SESSION['item'][$count][] = $_POST['pic_style']; > $_SESSION['item'][$count][] = $cost; > $_SESSION['item'][$count][] = $image; > > $count += 1; > > $_SESSION['item'][$count][] = ...; > $_SESSION['item'][$count][] = ...; > // etc. > > > Personally, I'd be inclined to use string indexes that indicate what's in each > element, to avoid having to remember somehow which numeric index corresponds to which attribute; so: > > $_SESSION['item'][$count]['phone'] = $_POST['phone']; > $_SESSION['item'][$count]['category'] = $_POST['category']; > $_SESSION['item'][$count]['copy'] = $_POST['copy']; > $_SESSION['item'][$count]['pic_style'] = $_POST['pic_style']; > $_SESSION['item'][$count]['cost'] = $cost; > $_SESSION['item'][$count]['image'] = $image; > > $count += 1; > > $_SESSION['item'][$count]['phone'] = ...; > $_SESSION['item'][$count]['category'] = ...; > // etc. > Thanks for all the help guys. I now have a better understanding of multi dimensional arrays and can use it for what I'm trying to accomplish. This list is the greatest!! Thanks, Ed

« previous php.general (#239415) next »