1

I've got a multidimensional array, which refers to itself multiple times. like:

$foo = array(
  0 => array(
    & $foo[1],
    & $foo[2],
    'bar',
  ),
  1 => array(
    & $foo[0],
    & $foo[2],
    'bar',
  ),
  2 => array(
    & $foo[0],
    & $foo[1],
    'bar',
  ),
)

Is there a way to get the size (in bites or in amout of elements) of this array?

Kind Regards,

Tempestas Ludi.

3
  • 2
    @vusan PHP doesn't mind extra commas at the end of an array. Commented Dec 29, 2012 at 9:00
  • It's a fairly straightforward recursive algorithm. What have you tried? Commented Dec 29, 2012 at 9:01
  • What is expected size (elements) of this example? 12 (3 main level + 9 from child arrays), 9 (only child arrays), 6 (3 main level + 3 non references from child), 3 (main level only) or 3 (non references from child arrays)? Commented Dec 29, 2012 at 9:57

1 Answer 1

1

You can serialize the array, then determine the bytes using: mb_strlen()

$serialized = serialize($foo);
echo mb_strlen($serialized,'8bit');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.