This is a discussion on help with arrays within the PHP General forums, part of the PHP Programming Forums category; Hey people. I've got an array like this: [0] => Array ( [0] => j [fname] => j [1] => ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hey people.
I've got an array like this: [0] => Array ( [0] => j [fname] => j [1] => j [lname] => j [2] => jj [state] => jj [3] => j@domain.com [email] => j@domain.com [4] => 0 [newsletter] => 0 ) Some cells might be empty so i want to replace every empty cell with " ". I can easily do this with just the numerical index but I can't figure out how to do the textual indices also. Someone have a clue? Thanks, Chris. |
|
|||
|
It doesn't get much simpler :)
foreach( $data as $key => $value ) { if( $value == '' ) { $data[$key] = ' ' } } Cheers, Rob. On Tue, 2003-09-23 at 16:38, Chris W. Parker wrote: > Hey people. > > I've got an array like this: > > > [0] => Array > ( > [0] => j > [fname] => j > [1] => j > [lname] => j > [2] => jj > [state] => jj > [3] => j@domain.com > [email] => j@domain.com > [4] => 0 > [newsletter] => 0 > ) > > Some cells might be empty so i want to replace every empty cell with > " ". I can easily do this with just the numerical index but I can't > figure out how to do the textual indices also. > > Someone have a clue? > > > Thanks, > Chris. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- ..------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------' |
|
|||
|
Of course, you could do it in a much more cryptic way... just for fun.
:-) INPUT: <?php $a = array( '0' => 'j', 'fname' => 'j', '1' => 'j', 'lname' => 'j', '2' => 'jj', 'state' => '', '3' => 'j@domain.com', 'email' => 'j@domain.com', '4' => '0', 'newsletter' => '0', ); array_walk($a, create_function('&$v', '$v = ($v=="")?" ":$v;')); print_r($a); ?> OUTPUT: petej@computer$ php -f test.php Array ( [0] => j [fname] => j [1] => j [lname] => j [2] => jj [state] => [3] => j@domain.com [email] => j@domain.com [4] => 0 [newsletter] => 0 ) Chris W. Parker wrote: > Hey people. > > I've got an array like this: > > > [0] => Array > ( > [0] => j > [fname] => j > [1] => j > [lname] => j > [2] => jj > [state] => jj > [3] => j@domain.com > [email] => j@domain.com > [4] => 0 > [newsletter] => 0 > ) > > Some cells might be empty so i want to replace every empty cell with > " ". I can easily do this with just the numerical index but I can't > figure out how to do the textual indices also. > > Someone have a clue? > > > Thanks, > Chris. > |
|
|||
|
On Tue, 2003-09-23 at 17:06, Pete James wrote:
> Of course, you could do it in a much more cryptic way... just for fun. > AKA Perl style ;) -- ..------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------' |