Is there any way of knowing when an array item has a subarray item?]]>Mr Oldies2013-10-24T21:39:44-00:00Re: detection of 2d array?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=183443&th=123229#msg_183443
> given the example>>>
>
> array=("item","photo"),
> array=("item",array=("photo1","photo2")),
> array=("item","photo")
>
> Is there any way of knowing when an array item has a subarray item?
>
is_array() shoulr be able to tell you if a variable is an array
$array=array("item", array("photo1","photo2"));
foreach($array as $key => $cell)
if(is_array($cell))
echo "cell {$key} has an array\n";
//Aho]]>J.O. Aho2013-10-24T22:10:29-00:00Re: detection of 2d array?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=183444&th=123229#msg_183444
> On 24/10/13 23:39, richard wrote:
>> given the example>>>
>>
>> array=("item","photo"),
>> array=("item",array=("photo1","photo2")),
>> array=("item","photo")
>>
>> Is there any way of knowing when an array item has a subarray item?
>>
> is_array() shoulr be able to tell you if a variable is an array
>
> $array=array("item", array("photo1","photo2"));
>
> foreach($array as $key => $cell)
> if(is_array($cell))
> echo "cell {$key} has an array\n";
>
> see http://www.php.net/manual/en/function.is-array.php
thanks. I'll play with it and see what happens.]]>Mr Oldies2013-10-24T22:12:52-00:00Re: detection of 2d array?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=183448&th=123229#msg_183448
> given the example>>>
>
> array=("item","photo"),
> array=("item",array=("photo1","photo2")),
> array=("item","photo")
>
> Is there any way of knowing when an array item has a subarray item?
Yes. PHP contains several functions that can be used to determine the
type of a variable, and as an array element is just another variable,
these can be applied at the array element level.
--
Denis McMahon, denismfmcmahon@gmail.com]]>Denis McMahon2013-10-25T14:58:31-00:00Re: detection of 2d array?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=183454&th=123229#msg_183454
> On Thu, 24 Oct 2013 17:39:44 -0400, richard wrote:
>> given the example>>>
>>
>> array=("item","photo"),
>> array=("item",array=("photo1","photo2")),
>> array=("item","photo")
… which is not even syntactically valid PHP code …
>> Is there any way of knowing when an array item has a subarray item?
>
> Yes. PHP contains several functions that can be used to determine the
> type of a variable, and as an array element is just another variable,
> these can be applied at the array element level.
>
> http://www.php.net/manual/en/ref.var.php
Nonsense again. An array element is _not_ a variable. The correct answer
has been given by J.O. Aho.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>]]>Thomas 'PointedEars' 2013-10-26T00:37:58-00:00Re: detection of 2d array?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=183647&th=123229#msg_183647
$a=array(1,2,3,4=>array(3,4,5,7=>array(1)));
if (preg_match('/;a:[0-9]+:{/',serialize($a)))
{
echo 'I have more than one dimensions';
}
else
{
echo 'I have one demension';
}]]>Struchkov Vladimir2013-11-06T13:24:25-00:00Re: detection of 2d array?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=183656&th=123229#msg_183656
> I write short test for 2d dimension
>
>
> $a=array(1,2,3,4=>array(3,4,5,7=>array(1)));
> if (preg_match('/;a:[0-9]+:{/',serialize($a)))
> {
> echo 'I have more than one dimensions';
> }
> else
> {
> echo 'I have one demension';
> }
>
He was asking if a certain element of the first array is an array or
not; that's what is_array() is for.
J.O. has the best answer.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. jstucklex@attglobal.net
==================]]>Jerry Stuckle2013-11-06T22:04:22-00:00