Hey freakers,
I am stumbling upon a problem I dont know how to solve, so here it is. Its something of a luxery problem, even if I cant fix it I dont mind. However, I would like to know if its possible.
What I would like is this. I have this array:
Array ( [0] => Array ( [comment_id] => 1 [user] => Array ( [id] => 1 [name] => Davey Kulter [avatar] => /assets/img/user_images/1_avi.jpg ) [parent_id] => 0 [time] => March 19th, 5:24AM [content] => Some text ) [1] => Array ( [comment_id] => 2 [user] => Array ( [id] => 2 [name] => Jason Biondo [avatar] => /assets/img/user_images/2_avi.jpg ) [parent_id] => 1 [time] => March 19th, 5:24AM [content] => Some text ) [2] => Array ( [comment_id] => 5 [user] => Array ( [id] => 3 [name] => Rudolph [avatar] => /assets/img/user_images/3_avi.jpg ) [parent_id] => 1 [time] => March 19th, 5:45AM [content] => Some text ) [3] => Array ( [comment_id] => 6 [user] => Array ( [id] => 1 [name] => Davey Kulter [avatar] => /assets/img/user_images/1_avi.jpg ) [parent_id] => 1 [time] => March 19th, 5:45AM [content] => Some text ) [4] => Array ( [comment_id] => 4 [user] => Array ( [id] => 1 [name] => Davey Kulter [avatar] => /assets/img/user_images/1_avi.jpg ) [parent_id] => 2 [time] => March 19th, 5:25AM [content] => Some text ) [5] => Array ( [comment_id] => 3 [user] => Array ( [id] => 3 [name] => Rudolph [avatar] => /assets/img/user_images/3_avi.jpg ) [parent_id] => 0 [time] => March 19th, 5:25AM [content] => Some text ) [6] => Array ( [comment_id] => 7 [user] => Array ( [id] => 1 [name] => Davey Kulter [avatar] => /assets/img/user_images/1_avi.jpg ) [parent_id] => 0 [time] => March 19th, 7:47AM [content] => Some text ) )
This is an array of comments on a blog. Regardless, I would like to focus this area in specific:
Array ( [0] => Array ( [comment_id] => 1 [user] => Array ( [id] => 1 [name] => Davey Kulter [avatar] => /assets/img/user_images/1_avi.jpg ) [parent_id] => 0 [time] => March 19th, 5:24AM [content] => Some text ) [1] => Array ( [comment_id] => 2 [user] => Array ( [id] => 2 [name] => Jason Biondo [avatar] => /assets/img/user_images/2_avi.jpg ) [parent_id] => 1 [time] => March 19th, 5:24AM [content] => Some text ) [2] => Array ( [comment_id] => 5 [user] => Array ( [id] => 3 [name] => Rudolph [avatar] => /assets/img/user_images/3_avi.jpg ) [parent_id] => 1 [time] => March 19th, 5:45AM [content] => Some text ) [3] => Array ( [comment_id] => 6 [user] => Array ( [id] => 1 [name] => Davey Kulter [avatar] => /assets/img/user_images/1_avi.jpg ) [parent_id] => 1 [time] => March 19th, 5:45AM [content] => Some text ) [4] => Array ( [comment_id] => 4 [user] => Array ( [id] => 1 [name] => Davey Kulter [avatar] => /assets/img/user_images/1_avi.jpg ) [parent_id] => 2 [time] => March 19th, 5:25AM [content] => Some text ) )
as you can see from parent_id, the first is a comment and the rest are replies to that comment (I only allow one level of replies, so no reply to a reply).
However, if I loop through this array in a foreach() loop and I am at array key [4], how do I find out what the comment_id of the previous array key where parent_id = 0. SO, what I would like is a function that would, in this case, return id = 1.
If I dont make sense, I am sorry. Its quite weird xD
Thanks regardless