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













-2















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










share|improve this question
























  • 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
















-2















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










share|improve this question
























  • 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














-2












-2








-2








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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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


















  • 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

















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











1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer




















  • 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










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
);



);













draft saved

draft discarded


















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









0














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.






share|improve this answer




















  • 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















0














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.






share|improve this answer




















  • 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













0












0








0







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








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












  • 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






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.



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript