Jump to content

Stepping through Multidimension Array


jedeye

Recommended Posts

i have tried many different built in functions from the php manual to no avail...

 

i have a class with a function to return the values from a query in an array...when it returns it returns as a multidimensional array

 

function code:

function getModelSpecs() {

	$array_of_specs = array();
	$i = 0;		

	$result = pg_query($this->dbConnection,self::stringGetModelSpecsSQL);

	while( $rows = pg_fetch_row($result) ){

		$specs = new ModelSpecsDTO();
		$specs->spec_id = $rows[0];
		$specs->spec_name = $rows[1];
		$specs->spec_description = $rows[2];
		$specs->css_category_name = $rows[3];
		$specs->spec_index = $rows[4];
		$array_of_specs[$i] = $specs;
		$i++;

	}

	return $array_of_specs;
}

 

my return values from "var_dump"

array(4) { [0]=> object(ModelSpecsDTO)#2 (5) { ["spec_id"]=> string(1) "1" ["spec_name"]=> string(5) "Width" ["spec_description"]=> string(13) "Product Width" ["css_category_name"]=> NULL ["spec_index"]=> string(1) "0" } [1]=> object(ModelSpecsDTO)#3 (5) { ["spec_id"]=> string(1) "2" ["spec_name"]=> string(6) "Height" ["spec_description"]=> string(14) "Product Height" ["css_category_name"]=> NULL ["spec_index"]=> string(1) "1" } [2]=> object(ModelSpecsDTO)#4 (5) { ["spec_id"]=> string(1) "3" ["spec_name"]=> string(5) "Depth" ["spec_description"]=> string(13) "Product Depth" ["css_category_name"]=> NULL ["spec_index"]=> string(1) "2" } [3]=> object(ModelSpecsDTO)#5 (5) { ["spec_id"]=> string(2) "-1" ["spec_name"]=> string(4) "Misc" ["spec_description"]=> string(13) "LSI Misc Data" ["css_category_name"]=> NULL ["spec_index"]=> string(1) "3" } } 

 

The problem is...

 

All i want to is the spec_name value from each array, but having a hell of a time trying to figure out the algorithm to step through the array and pull only that value for each array.

Any help is greatly appreciated...

Link to comment
Share on other sites

It makes it hard to analyze the array when you put it all in one line like that. Could you do a print_r() and post the results. Also, either get the output directly in the HTML source (which will have the line breaks) or put the output inside PRE tags so it will display with line-breaks in the output.

Link to comment
Share on other sites

@mj> that was a print_r

 

@wild> OMG.. i feel real dumb, thank you. i was totally trying to over complicate it by trying to slice the array n such

I also tried that exact step... however, i put it outside a loop for testing, just to see if it would spit out what i needed...

$connectDAO = daoFactory::getModelSpecs();

$model_specs = $connectDAO->getModelSpecs();

$model_specs->spec_name;

 

thanks again..

Link to comment
Share on other sites

When you use pring_r() or var_dump(), inclose them inside <pre> tags, to get the desired output.

 

Or just view the output in the HTML source code (i.e. right-click View Page Source).

 

That seems to soar over the heads of newbies!!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.