Jump to content

Problem Trying To Look Through Array?


Solarpitch

Recommended Posts

Hey Guys,

 

I'm after creating an array of some description and cant seem to figure out how to get the data from it:

 

The array looks like this...

 

Array
(
[1] => Array
(
[0] => stdClass Object
(
[id] => 1
[question] => Sprint Planning duration: between 2-4 hours
[question_category] => 1
[created] =>
[category_name] => Sprint Planning
[question_id] => 1
)
[1] => stdClass Object
(
[id] => 1
[question] => Team used Roman Voting to agree what user stories will be part of the sprint
[question_category] => 1
[created] =>
[category_name] => Sprint Planning
[question_id] => 2
)
[2] => stdClass Object
(
[id] => 1
[question] => Backlog is correctly prioritized
[question_category] => 1
[created] =>
[category_name] => Sprint Planning
[question_id] => 3
)
[3] => stdClass Object
(
[id] => 1
[question] => Team discuss user story and acceptance criteria for each story and have clear understanding of what is expected
[question_category] => 1
[created] =>
[category_name] => Sprint Planning
[question_id] => 4
)
[4] => stdClass Object
(
[id] => 1
[question] => Each user story in the sprint is Sprint Ready
[question_category] => 1
[created] =>
[category_name] => Sprint Planning
[question_id] => 5
)
[5] => stdClass Object
(
[id] => 1
[question] => There are between 5-20 user stories in the sprint
[question_category] => 1
[created] =>
[category_name] => Sprint Planning
[question_id] => 6
)
)
[2] => Array
(
)
[3] => Array
(
)
)

 

I'm trying this but get the below error. $get_questions holds the above array.

 

<?php foreach($get_questions as $question){
echo $question->category_name;
?>

 

error:

A PHP Error was encountered

 

Severity: Notice

Message: Trying to get property of non-object

Edited by Solarpitch
Link to comment
Share on other sites

If we add some proper indenting to that result, it'll be easier to see what's wrong:

Array (
[1] => Array (
	[0] => stdClass Object (
		[id] => 1
		[question] => Sprint Planning duration: between 2-4 hours
		[question_category] => 1
		[created] =>
		[category_name] => Sprint Planning
		[question_id] => 1
	)
	[1] => stdClass Object (
		[id] => 1
		[question] => Team used Roman Voting to agree what user stories will be part of the sprint
		[question_category] => 1
		[created] =>
		[category_name] => Sprint Planning
		[question_id] => 2
	)
	[2] => stdClass Object (
		[id] => 1
		[question] => Backlog is correctly prioritized
		[question_category] => 1
		[created] =>
		[category_name] => Sprint Planning
		[question_id] => 3
	)
	[3] => stdClass Object (
		[id] => 1
		[question] => Team discuss user story and acceptance criteria for each story and have clear understanding of what is expected
		[question_category] => 1
		[created] =>
		[category_name] => Sprint Planning
		[question_id] => 4
	)
	[4] => stdClass Object (
		[id] => 1
		[question] => Each user story in the sprint is Sprint Ready
		[question_category] => 1
		[created] =>
		[category_name] => Sprint Planning
		[question_id] => 5
	)
	[5] => stdClass Object (
		[id] => 1
		[question] => There are between 5-20 user stories in the sprint
		[question_category] => 1
		[created] =>
		[category_name] => Sprint Planning
		[question_id] => 6
	)
)
[2] => Array ()
[3] => Array ()
)

 

Hopefully that helps you in spotting the problem? ;)

Link to comment
Share on other sites

Apologies, arrays are not my strong point.. indenting it would be a task in itself. And I still havent a clue what the problem is.

 

EDIT: I'm thinking I might need to go down the route of something like but not really sure.

 

<?php foreach($get_questions as $key => $value){ ?>

..

Edited by Solarpitch
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.