Jump to content

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

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.

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

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.

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.