Or so I thought!
I'm trying to iterate through an array and test if any of the values are NULL or ""
and if they are I just want to insert XXX
I've tried many things and I'm so confused I'd appreciate any help at all.
Super simple
Moderator: General Moderators
Re: Super simple
Code: Select all
foreach($yourArray as $key=>$value)
{
if(is_null($value) or $value === '')
$yourArray[$key] = 'XXX';
}Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Super simple
If you also want to consider 0, false and empty arrays as "empty", then you can replace
with
Code: Select all
if(is_null($value) or $value === '')Code: Select all
if(empty($value))Re: Super simple
I really appreciate the help thanks when I try and run this it gives me
"Fatal error: Can't use function return value in write context in C:\xampp\htdocs\madlib.php on line 36"
For you though that would be line 4 I think it's the line with "$ yourArray[$key] = 'XXX';"
Again it looks like it should work to me and I guess that's why I'm so frustrated.
"Fatal error: Can't use function return value in write context in C:\xampp\htdocs\madlib.php on line 36"
For you though that would be line 4 I think it's the line with "$ yourArray[$key] = 'XXX';"
Again it looks like it should work to me and I guess that's why I'm so frustrated.
I TAKE IT BACK! I should have copied and pasted I was doing "$ yourArray($key) = 'XXX';"
instead of "$ yourArray[$key] = 'XXX';" which does work so thank you.