giwrgos Posted November 14, 2012 Share Posted November 14, 2012 Hello everyone. i'm new on this site and also new on PHP coding. I want to make a loop using the values of an object (name of the object is test). my object has categoryid,parentid and i want to make something like this forearch(categoryid){ foreach(parentid){ if (parentid == categoryid){ do something } } } Can anyone help me to do this loop? Thank you Quote Link to comment Share on other sites More sharing options...
Jessica Posted November 14, 2012 Share Posted November 14, 2012 foreach works on arrays and objects. If your object has an array called categoryid, you can use foreach on it. Otherwise, you need to explain what you're trying to do. You can't foreach on a single value. Quote Link to comment Share on other sites More sharing options...
giwrgos Posted November 14, 2012 Author Share Posted November 14, 2012 (edited) Im using PDO where i'm getting values from the database as an object "setFetchMode(PDO::FETCH_OBJ)" Then i return this values in the test variable and i want to make a foreach loop for any of the files that the test has. for example i can make foreach (test->categoryid as $categoryvalue) ? Edited November 14, 2012 by giwrgos Quote Link to comment Share on other sites More sharing options...
Jessica Posted November 14, 2012 Share Posted November 14, 2012 Did you try it? You're still not making sense. Is categoryid an array? If so, it should probably have a better name, but if not, why would you WANT to loop through it? Quote Link to comment Share on other sites More sharing options...
giwrgos Posted November 14, 2012 Author Share Posted November 14, 2012 Did you try it? You're still not making sense. Is categoryid an array? If so, it should probably have a better name, but if not, why would you WANT to loop through it? categoryid is a field. if a make this loop fooreach ($test as $row){ echo $row->categoryid; } it will print all the values of the field categoryid Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted November 14, 2012 Share Posted November 14, 2012 dude.... foreach($thingYouAreTryingToDo as $someQuestion){ foreach($someQuestion as $question => $answer){ if($question == 'makes no sense'){ $answer = 'impossible to give'; } } } Jassica has already asked you to provide an explination as your question, as it stands, makes no sense. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.