my class in php contains an array -> mysql_fields. How do i go about extracting the info from the array?

giving a print_r($sub_details->mysql_fields) works as expected while,

but foreach($sub_details->mysql_fields as $key -> $value)
{

echo $key."->".$value;
}

doesnt work.

How do i got about iterating through the arrary?

Recommended Answers

All 2 Replies

it seems that if i ask it to echo explicitly like

$sub_details->mysql_fields it works but if i use $sub_details->mysql_fields[0] it doesnt.

ironic.

With a foreach, $key is the key of the array and obviously, $value is the value so for

$array = array('key1' => 'value1', 'key2' => 'value2');

foreach will act like this

foreach ($array as $key => $value) {
  echo $key . '=' . $value; // key1 = value1, etc.
}

http://php.net/foreach

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.