|
Posted by Richard on 02/15/07 15:40
Rik <luiheidsgoeroe@hotmail.com> writes:
> fabrice régnier <regnier.fab@free.fr> wrote:
>>> Either by a loop:
>>> $filtered = array()
>>> foreach ($res as $key => $item){
>>> if($res['age']!=0) $filtered[] = $item;
>>> //or preserve keys by $filtered[$key] = $item;
>>> }
>>> Or indeed by array_filter:
>>> $filtered = array_filter($res,create_funtion('$v,$k','return
>>> $v['age']!=0;'));
>>
>> I've tested your 2 solutions and both doesn't work.
>>
>> First solution gives me an empty array as a result.
>> Second solution gives me a syntaxic error.
>>
>> Maybe you forgot something ? Thanx, anyway.
>
>
> Allthough I usually respond with a lot of code, I do not test
> this. It's an insight in how you can solve your problem, if you want
> me to write your code for you you'll have to pay the usual
> rate. Getting an answer is not like paying for a full working code,
> you'll have to do your own error-hunting and implementation. I
> suggest some reading material:
> <http://www.catb.org/~esr/faqs/smart-questions.html>.
>
> FYI: What was wrong?
> First example:
> if($res['age']!=0) $filtered[] = $item;
> should be
> if($item['age']!=0) $filtered[] = $item;
>
> Example:
> $filtered = array_filter($res,create_funtion('$v,$k','return
> ($v[\'age\']!=0);'));
>
> Both mistakes are easily spotted with a minimum amount of effort.
If it's not a beginner asking beginner's questions .....
Navigation:
[Reply to this message]
|