TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   2-d arrays -- issues of printing and deleting (http://www.talkphp.com/absolute-beginners/2902-2-d-arrays-issues-printing-deleting.html)

Dave 06-05-2008 04:16 AM

2-d arrays -- issues of printing and deleting
 
I have an array of arrays, like so:

$arr = array(array('blue','green','yellow'),
array('fall','winter','summer'),
array('Ford','GMC','Toyota')
)


I want to print_r(), say, only the seasons and the cars, how would I do this?

Also, how could I delete one of the arrays?

Thanks for your help!

Dave

SpYkE112 06-05-2008 07:43 AM

well,
PHP Code:

echo('<pre>');
print_r($arr[1]); //Seasons
print_r($arr[2]); //Cars
echo('</pre>'); 

To delete one, it would probaly require you to do some loop or stuff like that..

Wildhoney 06-05-2008 11:44 AM

To delete a part of the array use unset:

php Code:
unset($arr[1]);

Enfernikus 06-05-2008 11:45 AM

php.net/unset

PHP Code:

unset($arr[1]); 

The only issue is if I'm not mistaken is, the array will persist with the current numerical order - meaning it'll be something like this

PHP Code:

$arr[0]
$arr[2

you can use a combination of array_splice/array_merge to properly delete array elements and have them be in correct numerical order.


All times are GMT. The time now is 10:19 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0