NUmber of indentations in array?

Discuss the development of future releases of phpBB (phpBB 3.x minor releases) and MODing/Coding related questions.
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
harmlessgoat22
Supporter
Supporter
Posts: 316
Joined: 18 Sep 2007, 14:35
Real name: David
Contact:

NUmber of indentations in array?

Postby harmlessgoat22 » 14 Jun 2008, 16:14

Is there a function, or could I easily make a function, that figures out how deep a value is in an array? For example, $my_array['this']['that']['these']['those'] would produce a result of four, $my_other_array['hmm']['huh']['what'] would produce a result of three, etc.

That's like, I can't beat my neighbor in an argument, so instead I kill his dog.
-Best English Teacher Ever

A.I. BOT
New member
New member
Posts: 7
Joined: 13 Jun 2007, 22:02
Real name: Tyler King
Location: Newfoundland, Canada
Contact:

Re: NUmber of indentations in array?

Postby A.I. BOT » 16 Jun 2008, 17:56

- An all-in-one clan, ladder and tournament script.

harmlessgoat22
Supporter
Supporter
Posts: 316
Joined: 18 Sep 2007, 14:35
Real name: David
Contact:

Re: NUmber of indentations in array?

Postby harmlessgoat22 » 17 Jun 2008, 16:12

Thanks AI Bot, will test now.

EDIT: Works like a charm. Thank you very much.

That's like, I can't beat my neighbor in an argument, so instead I kill his dog.
-Best English Teacher Ever

User avatar
igorw
Past Contributor
Past Contributor
Posts: 1967
Joined: 01 Jun 2006, 20:48
Real name: Igor
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: NUmber of indentations in array?

Postby igorw » 17 Jun 2008, 16:45

Per the phpBB3 coding guidelines you could use sizeof instead of count. No real difference but perhaps worth a mention.

- we're poor!

harmlessgoat22
Supporter
Supporter
Posts: 316
Joined: 18 Sep 2007, 14:35
Real name: David
Contact:

Re: NUmber of indentations in array?

Postby harmlessgoat22 » 17 Jun 2008, 17:07

sizeof would be how many things...
eg
array(1 => 't, 2 => 'r')
would return 2. However, this is the depth, not the number of values.

That's like, I can't beat my neighbor in an argument, so instead I kill his dog.
-Best English Teacher Ever

User avatar
igorw
Past Contributor
Past Contributor
Posts: 1967
Joined: 01 Jun 2006, 20:48
Real name: Igor
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: NUmber of indentations in array?

Postby igorw » 17 Jun 2008, 17:46

sizeof is an alias of count. So maybe this is not what you're looking for. :P

- we're poor!

harmlessgoat22
Supporter
Supporter
Posts: 316
Joined: 18 Sep 2007, 14:35
Real name: David
Contact:

Re: NUmber of indentations in array?

Postby harmlessgoat22 » 17 Jun 2008, 21:49

No, I tested it and it works...I think its , COUNT_RECURSIVE that makes it work...so if Sizeof is an alias, I can do sizeof($my_array, COUNT_RECURSIVE) and it would be the same as count($my_array, COUNT_RECURSIVE)???

That's like, I can't beat my neighbor in an argument, so instead I kill his dog.
-Best English Teacher Ever

User avatar
igorw
Past Contributor
Past Contributor
Posts: 1967
Joined: 01 Jun 2006, 20:48
Real name: Igor
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: NUmber of indentations in array?

Postby igorw » 17 Jun 2008, 22:15


- we're poor!

harmlessgoat22
Supporter
Supporter
Posts: 316
Joined: 18 Sep 2007, 14:35
Real name: David
Contact:

Re: NUmber of indentations in array?

Postby harmlessgoat22 » 17 Jun 2008, 22:22

Oh...so that's not what I want :(

That's like, I can't beat my neighbor in an argument, so instead I kill his dog.
-Best English Teacher Ever

User avatar
igorw
Past Contributor
Past Contributor
Posts: 1967
Joined: 01 Jun 2006, 20:48
Real name: Igor
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: NUmber of indentations in array?

Postby igorw » 17 Jun 2008, 22:56

Last edited by igorw on 12 Jan 2015, 23:59, edited 2 times in total.
Reason: changed a bit

- we're poor!

harmlessgoat22
Supporter
Supporter
Posts: 316
Joined: 18 Sep 2007, 14:35
Real name: David
Contact:

Re: NUmber of indentations in array?

Postby harmlessgoat22 » 18 Jun 2008, 01:01

Thank you. I will check if it works in a moment ;)

That's like, I can't beat my neighbor in an argument, so instead I kill his dog.
-Best English Teacher Ever


[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Return to “phpBB Development discussion”

Who is online

Users browsing this forum: No registered users and 12 guests