Jump to content


Photo

Help exploring an "unknown" array *solved*


  • Please log in to reply
3 replies to this topic

#1 alhefner

alhefner
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 19 October 2006 - 08:14 PM

I am really new to php and need a little help exploring an array.

I am running a script that uses the $_SESSION global as a multi-dimensional array. I don't know how many dimensions the array has.

What I would like to do is loop through all of the array and echo the variable name, key names, and values.

This will help me in my efforts to develope simple mods to my site without duplicating information or stepping on information already stored in the $_SESSION global.

Thanks in advance!
Al

#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 19 October 2006 - 08:28 PM

well to loop thru the array you can use a foreach statement.

<?php
foreach($_SESSION as $key => $val){
  if(is_array($val)){
    foreach($val as $key2 => $val2){
      echo "$key: $key2 -- $val2<br>";
    }
  } else {
    echo "$key: $val<br>";
  }
}
?>

Ray

#3 alhefner

alhefner
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 19 October 2006 - 08:40 PM

The array check was missing from my first attempt. Thanks! I copied your code "as is" and am coming up with a blank page. I'll do some more exploration.

Thanks again!

Al

#4 alhefner

alhefner
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 19 October 2006 - 08:57 PM

Don't I feel like a dummy! Forgot to "start the session"!!

No session = no session variables!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users