Jump to content

How I Can Make A Loop From The Values Of An Object?


giwrgos

Recommended Posts

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

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

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.