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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.