Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #11578 > unrolled thread

detection of 2d array?

Started byrichard <noreply@example.com>
First post2013-10-24 17:39 -0400
Last post2013-11-06 17:04 -0500
Articles 7 — 6 participants

Back to article view | Back to comp.lang.php


Contents

  detection of 2d array? richard <noreply@example.com> - 2013-10-24 17:39 -0400
    Re: detection of 2d array? "J.O. Aho" <user@example.net> - 2013-10-25 00:10 +0200
      Re: detection of 2d array? richard <noreply@example.com> - 2013-10-24 18:12 -0400
    Re: detection of 2d array? Denis McMahon <denismfmcmahon@gmail.com> - 2013-10-25 14:58 +0000
      Re: detection of 2d array? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-26 02:37 +0200
    Re: detection of 2d array? Struchkov Vladimir <struchkov@gmail.com> - 2013-11-06 05:24 -0800
      Re: detection of 2d array? Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-06 17:04 -0500

#11578 — detection of 2d array?

Fromrichard <noreply@example.com>
Date2013-10-24 17:39 -0400
Subjectdetection of 2d array?
Message-ID<7x8n4ftkdpt.13nclqr4ren29.dlg@40tude.net>
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?

[toc] | [next] | [standalone]


#11579

From"J.O. Aho" <user@example.net>
Date2013-10-25 00:10 +0200
Message-ID<bctk6lFrenvU1@mid.individual.net>
In reply to#11578
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

-- 

  //Aho

[toc] | [prev] | [next] | [standalone]


#11580

Fromrichard <noreply@example.com>
Date2013-10-24 18:12 -0400
Message-ID<1ofdptaq6r1do$.7zj8tk7n3qs4.dlg@40tude.net>
In reply to#11579
On Fri, 25 Oct 2013 00:10:29 +0200, J.O. Aho wrote:

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

[toc] | [prev] | [next] | [standalone]


#11584

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-10-25 14:58 +0000
Message-ID<l4e0un$99a$2@dont-email.me>
In reply to#11578
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")
> 
> 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

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#11590

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-10-26 02:37 +0200
Message-ID<7044722.OSoFHnGXHP@PointedEars.de>
In reply to#11584
Denis McMahon wrote:

> 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>

[toc] | [prev] | [next] | [standalone]


#11739

FromStruchkov Vladimir <struchkov@gmail.com>
Date2013-11-06 05:24 -0800
Message-ID<9d10d1be-f909-4a4d-989d-68ce4ecdbc4b@googlegroups.com>
In reply to#11578
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';
}

[toc] | [prev] | [next] | [standalone]


#11748

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-11-06 17:04 -0500
Message-ID<l5eed4$uo0$2@dont-email.me>
In reply to#11739
On 11/6/2013 8:24 AM, Struchkov Vladimir wrote:
> 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
==================

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web