/    Sign up×
Community /Pin to ProfileBookmark

Getting a record set from associative array

Hello

I am dealing with a problem and having a hard time solving it. So need your help!

Imagine I have a comment section in my website, where there are two types of role “member” and “staff”. Both roles can post comment. I want to get the datetime of the [B]first[/B] post made by the [B]opposite[/B] role. For example, in the following array the latest post was made by “aaa” at 1433566756. So, how do I programitically get the first post made by the opp role (i.e. post made by ccc at 1433566752)

Note: The following array is in reverse chronological order. Meaning, the latest post appears on top. Also, to make it less confusing, I have used unique datetime for each record below.

[CODE]
Array
(
[0] => Array
(
[role] => member
[username] => aaa
[datetime] => 1433566756
)

[1] => Array
(
[role] => member
[username] => aaa
[datetime] => 1433566755
)

[2] => Array
(
[role] => staff
[username] => ccc
[datetime] => 1433566754
)

[3] => Array
(
[role] => staff
[username] => ccc
[datetime] => 1433566753
)

[4] => Array
(
[role] => staff
[username] => ccc
[datetime] => 1433566752
)

[5] => Array
(
[role] => member
[username] => aaa
[datetime] => 1433566751
)

)

[/CODE]

please help…

thanks in advance

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 06.2015 — How about just using array_reverse(), and then a foreach() loop until you find the first sub-array of the desired type?
×

Success!

Help @phantom007 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...