|
Posted by -Lost on 12/21/06 16:29
"Els" <els.aNOSPAM@tiscali.nl> wrote in message
news:1wya57gvvqad3.11ghuwvp7k4p7.dlg@40tude.net...
> Michael Fesser wrote:
>
>> .oO(Els)
>>
>>>Could I mix those two things, like so:
>>>$values = array(range(1, 4),17,30);
>>
>> That would make the array returned by range() a sub-array of $values,
>> which won't work as expected with in_array(). To solve that you could
>>
>> * use array_merge() to merge both arrays together before calling
>> in_array()
>> * write a function in_array_recursive() to search in a nested array
>> structure if necessary
>
> Sounds great, but as I am a total newbie, I think I'd go for the
> array_merge() function though, it seems (from where I'm standing)
> simpler than the recursive thing.
>
> Would this be how it works?
>
> $array1 = range(1,4);
> $array2 = array(17,30);
> $values = array_merge($array1,$array2);
> if (in_array($a,$values){
> echo "bingo";
> }
Exactly. You are missing a ) though.
> PHP.net gave a caution about the range() function:
> "In PHP versions 4.1.0 through 4.3.2, range() sees numeric strings as
> strings and not integers. Instead, they will be used for character
> sequences. For example, "4242" is treated as "4"."
>
> Would that cause trouble if I'd have
> $array = range(31,47);
> ?
That would cause problems only if you passed strings to range() instead of integers.
-Lost
Navigation:
[Reply to this message]
|