stdClass Object foreach PHP loopHow can I prevent SQL injection in PHP?How does the Java 'for each' loop work?Deleting an element from an array in PHPWhat is stdClass in PHP?Reference — What does this symbol mean in PHP?stdClass Object foreach PHPIs there a reason for C#'s reuse of the variable in a foreach?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?2 stdClass Object foreach PHP
Could you fall off a planet if it was being accelerated by engines?
Chandra exiles a card, I play it, it gets exiled again
How far can gerrymandering go?
Active wildlife outside the window- Good or Bad for Cat psychology?
Tricolour nonogram
Find the closest three-digit hex colour
Calculus, water poured into a cone: Why is the derivative non-linear?
Enterprise Layers and Naming Conventions
Is it possible to alias a column based on the result of a select+where?
Which coach station is easily accessible from Heathrow Airport?
ATMEGA328P-U vs ATMEGA328-PU
Installed software from source, how to say yum not to install it from package?
Does friction always oppose motion?
Why was Pan Am Flight 103 flying over Lockerbie?
Is it beneficial to use a crop sensor camera with a full frame telezoom?
Finding MacCready
Is it OK to throw pebbles and stones in streams, waterfalls, ponds, etc.?
Which high-degree derivatives play an essential role?
Why doesn't SpaceX land boosters in Africa?
Cat files in subfolders in order given by a list
LaTeX Make Word Appear
What verb goes with "coup"?
What is the lowest possible AC?
Where to connect the fuse and why?
stdClass Object foreach PHP loop
How can I prevent SQL injection in PHP?How does the Java 'for each' loop work?Deleting an element from an array in PHPWhat is stdClass in PHP?Reference — What does this symbol mean in PHP?stdClass Object foreach PHPIs there a reason for C#'s reuse of the variable in a foreach?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?2 stdClass Object foreach PHP
Been searching for a solution for my problem. Seams meny has the same q as me, but still haven't got a solution for my problem.
I have a stdClass Object that needs to be printed out in a foreach or somlike like that.
Here is a cut of the result i get with a "print_r($result)".
Array
(
[0] => stdClass Object
(
[id] => 1
[itemDescription] => I
[itemImage] => 2131099833
[itemName] => ABOOD
[itemPrice] => 8
[itemQuantity] => 1
[itemUid] => 1007
[orders] => stdClass Object
(
[date_created] => 0
[id] => 1
[ordered] =>
)
)
[1] => stdClass Object
(
[id] => 2
[itemDescription] =>
[itemImage] => 2131099833
[itemName] => PAPAYA
[itemPrice] => 8
[itemQuantity] => 1
[itemUid] => 1010
[orders] => stdClass Object
(
[date_created] => 0
[id] => 1
[ordered] =>
)
)
)
foreach ($result as $value)
foreach ($value as $key=>$value1)
if($key=="itemUid")
echo $value1;
if($key=="itemQuantity")
echo $value1;
any easy method
php foreach
add a comment |
Been searching for a solution for my problem. Seams meny has the same q as me, but still haven't got a solution for my problem.
I have a stdClass Object that needs to be printed out in a foreach or somlike like that.
Here is a cut of the result i get with a "print_r($result)".
Array
(
[0] => stdClass Object
(
[id] => 1
[itemDescription] => I
[itemImage] => 2131099833
[itemName] => ABOOD
[itemPrice] => 8
[itemQuantity] => 1
[itemUid] => 1007
[orders] => stdClass Object
(
[date_created] => 0
[id] => 1
[ordered] =>
)
)
[1] => stdClass Object
(
[id] => 2
[itemDescription] =>
[itemImage] => 2131099833
[itemName] => PAPAYA
[itemPrice] => 8
[itemQuantity] => 1
[itemUid] => 1010
[orders] => stdClass Object
(
[date_created] => 0
[id] => 1
[ordered] =>
)
)
)
foreach ($result as $value)
foreach ($value as $key=>$value1)
if($key=="itemUid")
echo $value1;
if($key=="itemQuantity")
echo $value1;
any easy method
php foreach
I guess a recursive function would work.
– Script47
Mar 25 at 16:40
2
You don't actually have an object, you have an array of objects. What have you tried to print out what you want? What is your expected result?
– Greg Schmidt
Mar 25 at 16:40
Have you triedget_object_vars
php.net/get-object-vars to get the array of properties and their values?
– Nik
Mar 25 at 16:41
What is your question? Please edit your request to include a question.
– colonelclick
Mar 25 at 16:45
add a comment |
Been searching for a solution for my problem. Seams meny has the same q as me, but still haven't got a solution for my problem.
I have a stdClass Object that needs to be printed out in a foreach or somlike like that.
Here is a cut of the result i get with a "print_r($result)".
Array
(
[0] => stdClass Object
(
[id] => 1
[itemDescription] => I
[itemImage] => 2131099833
[itemName] => ABOOD
[itemPrice] => 8
[itemQuantity] => 1
[itemUid] => 1007
[orders] => stdClass Object
(
[date_created] => 0
[id] => 1
[ordered] =>
)
)
[1] => stdClass Object
(
[id] => 2
[itemDescription] =>
[itemImage] => 2131099833
[itemName] => PAPAYA
[itemPrice] => 8
[itemQuantity] => 1
[itemUid] => 1010
[orders] => stdClass Object
(
[date_created] => 0
[id] => 1
[ordered] =>
)
)
)
foreach ($result as $value)
foreach ($value as $key=>$value1)
if($key=="itemUid")
echo $value1;
if($key=="itemQuantity")
echo $value1;
any easy method
php foreach
Been searching for a solution for my problem. Seams meny has the same q as me, but still haven't got a solution for my problem.
I have a stdClass Object that needs to be printed out in a foreach or somlike like that.
Here is a cut of the result i get with a "print_r($result)".
Array
(
[0] => stdClass Object
(
[id] => 1
[itemDescription] => I
[itemImage] => 2131099833
[itemName] => ABOOD
[itemPrice] => 8
[itemQuantity] => 1
[itemUid] => 1007
[orders] => stdClass Object
(
[date_created] => 0
[id] => 1
[ordered] =>
)
)
[1] => stdClass Object
(
[id] => 2
[itemDescription] =>
[itemImage] => 2131099833
[itemName] => PAPAYA
[itemPrice] => 8
[itemQuantity] => 1
[itemUid] => 1010
[orders] => stdClass Object
(
[date_created] => 0
[id] => 1
[ordered] =>
)
)
)
foreach ($result as $value)
foreach ($value as $key=>$value1)
if($key=="itemUid")
echo $value1;
if($key=="itemQuantity")
echo $value1;
any easy method
php foreach
php foreach
edited Mar 25 at 17:06
Faztrick Fazil Pv
asked Mar 25 at 16:37
Faztrick Fazil PvFaztrick Fazil Pv
2053 silver badges9 bronze badges
2053 silver badges9 bronze badges
I guess a recursive function would work.
– Script47
Mar 25 at 16:40
2
You don't actually have an object, you have an array of objects. What have you tried to print out what you want? What is your expected result?
– Greg Schmidt
Mar 25 at 16:40
Have you triedget_object_vars
php.net/get-object-vars to get the array of properties and their values?
– Nik
Mar 25 at 16:41
What is your question? Please edit your request to include a question.
– colonelclick
Mar 25 at 16:45
add a comment |
I guess a recursive function would work.
– Script47
Mar 25 at 16:40
2
You don't actually have an object, you have an array of objects. What have you tried to print out what you want? What is your expected result?
– Greg Schmidt
Mar 25 at 16:40
Have you triedget_object_vars
php.net/get-object-vars to get the array of properties and their values?
– Nik
Mar 25 at 16:41
What is your question? Please edit your request to include a question.
– colonelclick
Mar 25 at 16:45
I guess a recursive function would work.
– Script47
Mar 25 at 16:40
I guess a recursive function would work.
– Script47
Mar 25 at 16:40
2
2
You don't actually have an object, you have an array of objects. What have you tried to print out what you want? What is your expected result?
– Greg Schmidt
Mar 25 at 16:40
You don't actually have an object, you have an array of objects. What have you tried to print out what you want? What is your expected result?
– Greg Schmidt
Mar 25 at 16:40
Have you tried
get_object_vars
php.net/get-object-vars to get the array of properties and their values?– Nik
Mar 25 at 16:41
Have you tried
get_object_vars
php.net/get-object-vars to get the array of properties and their values?– Nik
Mar 25 at 16:41
What is your question? Please edit your request to include a question.
– colonelclick
Mar 25 at 16:45
What is your question? Please edit your request to include a question.
– colonelclick
Mar 25 at 16:45
add a comment |
1 Answer
1
active
oldest
votes
You could do something like this for each stdClass object in your array:
foreach ($stdClassObject as $propName => $propValue)
echo $propName . '->' . $propvalue;
As @arzhed stated in the comments, it's not necessary to use get_object_vars to iterate over the properties of an stdClass object.
1
The use of get_object_vars is unnecessary. As stated by the doc, "foreach works only on arrays and objects" php.net/manual/en/control-structures.foreach.php . Try it out
– arzhed
Mar 25 at 16:54
Cool, didn't know that, will update the answer. Thanks!
– William Janoti
Mar 25 at 17:02
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55342533%2fstdclass-object-foreach-php-loop%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could do something like this for each stdClass object in your array:
foreach ($stdClassObject as $propName => $propValue)
echo $propName . '->' . $propvalue;
As @arzhed stated in the comments, it's not necessary to use get_object_vars to iterate over the properties of an stdClass object.
1
The use of get_object_vars is unnecessary. As stated by the doc, "foreach works only on arrays and objects" php.net/manual/en/control-structures.foreach.php . Try it out
– arzhed
Mar 25 at 16:54
Cool, didn't know that, will update the answer. Thanks!
– William Janoti
Mar 25 at 17:02
add a comment |
You could do something like this for each stdClass object in your array:
foreach ($stdClassObject as $propName => $propValue)
echo $propName . '->' . $propvalue;
As @arzhed stated in the comments, it's not necessary to use get_object_vars to iterate over the properties of an stdClass object.
1
The use of get_object_vars is unnecessary. As stated by the doc, "foreach works only on arrays and objects" php.net/manual/en/control-structures.foreach.php . Try it out
– arzhed
Mar 25 at 16:54
Cool, didn't know that, will update the answer. Thanks!
– William Janoti
Mar 25 at 17:02
add a comment |
You could do something like this for each stdClass object in your array:
foreach ($stdClassObject as $propName => $propValue)
echo $propName . '->' . $propvalue;
As @arzhed stated in the comments, it's not necessary to use get_object_vars to iterate over the properties of an stdClass object.
You could do something like this for each stdClass object in your array:
foreach ($stdClassObject as $propName => $propValue)
echo $propName . '->' . $propvalue;
As @arzhed stated in the comments, it's not necessary to use get_object_vars to iterate over the properties of an stdClass object.
edited Mar 25 at 17:03
answered Mar 25 at 16:44
William JanotiWilliam Janoti
1,42610 silver badges25 bronze badges
1,42610 silver badges25 bronze badges
1
The use of get_object_vars is unnecessary. As stated by the doc, "foreach works only on arrays and objects" php.net/manual/en/control-structures.foreach.php . Try it out
– arzhed
Mar 25 at 16:54
Cool, didn't know that, will update the answer. Thanks!
– William Janoti
Mar 25 at 17:02
add a comment |
1
The use of get_object_vars is unnecessary. As stated by the doc, "foreach works only on arrays and objects" php.net/manual/en/control-structures.foreach.php . Try it out
– arzhed
Mar 25 at 16:54
Cool, didn't know that, will update the answer. Thanks!
– William Janoti
Mar 25 at 17:02
1
1
The use of get_object_vars is unnecessary. As stated by the doc, "foreach works only on arrays and objects" php.net/manual/en/control-structures.foreach.php . Try it out
– arzhed
Mar 25 at 16:54
The use of get_object_vars is unnecessary. As stated by the doc, "foreach works only on arrays and objects" php.net/manual/en/control-structures.foreach.php . Try it out
– arzhed
Mar 25 at 16:54
Cool, didn't know that, will update the answer. Thanks!
– William Janoti
Mar 25 at 17:02
Cool, didn't know that, will update the answer. Thanks!
– William Janoti
Mar 25 at 17:02
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55342533%2fstdclass-object-foreach-php-loop%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I guess a recursive function would work.
– Script47
Mar 25 at 16:40
2
You don't actually have an object, you have an array of objects. What have you tried to print out what you want? What is your expected result?
– Greg Schmidt
Mar 25 at 16:40
Have you tried
get_object_vars
php.net/get-object-vars to get the array of properties and their values?– Nik
Mar 25 at 16:41
What is your question? Please edit your request to include a question.
– colonelclick
Mar 25 at 16:45