help with arrays

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] => ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-23-2003
Chris W. Parker
 
Posts: n/a
Default help with arrays

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.
Reply With Quote
  #2 (permalink)  
Old 09-23-2003
Robert Cummings
 
Posts: n/a
Default Re: [PHP] help with arrays

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. |
`------------------------------------------------------------'
Reply With Quote
  #3 (permalink)  
Old 09-23-2003
Pete James
 
Posts: n/a
Default Re: [PHP] help with arrays

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=="")?"&nbsp;":$v;'));
print_r($a);

?>

OUTPUT:

petej@computer$ php -f test.php
Array
(
[0] => j
[fname] => j
[1] => j
[lname] => j
[2] => jj
[state] => &nbsp;
[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
> "&nbsp;". 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.
>

Reply With Quote
  #4 (permalink)  
Old 09-23-2003
Robert Cummings
 
Posts: n/a
Default Re: [PHP] help with arrays

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. |
`------------------------------------------------------------'
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:38 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0