/    Sign up×
Community /Pin to ProfileBookmark

hi, i have following array and the output is attached as attachment.

i need to altert this output so that it prints next person name in BY column, so the new output will be like

[code=html]
Rubab Admani Pending Review Farrukh Mushtaq 08/Jan/2014 12:03 PM
Farrukh Mushtaq Pending Assignment Beatriz Artal 08/Jan/2014 16:11 PM
Beatriz Artal In Progress Irfan Shafiq 08/Jan/2014 16:48 PM
[/code]

thanks in advance.

[code=php]Array
(
[pendingReview] => Array
(
[by] => Rubab Admani
[date] => 2014-01-08 12:03:45
)

[pendingAssignment] => Array
(
[by] => Farrukh Mushtaq
[date] => 2014-01-08 16:11:21
)

[inProgress] => Array
(
[by] => Beatriz Artal
[date] => 2014-01-08 16:48:27
)

[finalReviewing] => Array
(
[by] => Irfan Shafiq
[date] => 2014-01-09 11:01:26
)

[readyToSubmit] => Array
(
[by] => Beatriz Artal
[date] => 2014-01-09 13:37:26
)

)[/code]

[ATTACH]15963[/ATTACH]

[canned-message]attachments-removed-during-migration[/canned-message]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmFeb 03.2014 — Where is the "BY column"?
Copy linkTweet thisAlerts:
@NoEffinWayFeb 03.2014 — Your question is a little confusing but I think what you want is:
[code=php]
<?php
$arr = Array
(
"pendingReview" => Array
(
"by" => "Rubab Admani",
"date" => "2014 - 01 - 08 12:03:45"
),

"pendingAssignment" => Array
(
"by" => "Farrukh Mushtaq",
"date" => "2014 - 01 - 08 16:11:21"
),

"inProgress" => Array
(
"by" => "Beatriz Artal",
"date" => "2014 - 01 - 08 16:48:27"
),

"finalReviewing" => Array
(
"by" => "Irfan Shafiq",
"date" => "2014 - 01 - 09 11:01:26"
),

"readyToSubmit" => Array
(
"by" => "Beatriz Artal",
"date" => "2014 - 01 - 09 13:37:26"
)

);

$display = "";

foreach($arr AS $status => $info){
preg_match_all("/[A-Z]?[a-z]+/",$status,$statusBits);
$status = implode(" ",$statusBits[0]);
$status = ucwords($status);
$display = str_replace("|nxtname|",$info['by'],$display);
$display .= "{$info['by']} {$status} |nxtname| {$info['date']}n";
}

echo $display;
[/code]


This outputs (I wasn't sure how you wanted to handle the last one, where there is no next person.):
<i>
</i>Rubab Admani Pending Review Farrukh Mushtaq 2014 - 01 - 08 12:03:45
Farrukh Mushtaq Pending Assignment Beatriz Artal 2014 - 01 - 08 16:11:21
Beatriz Artal In Progress Irfan Shafiq 2014 - 01 - 08 16:48:27
Irfan Shafiq Final Reviewing Beatriz Artal 2014 - 01 - 09 11:01:26
Beatriz Artal Ready To Submit |nxtname| 2014 - 01 - 09 13:37:26
Copy linkTweet thisAlerts:
@anirban09PMar 07.2014 — Arrays can be used in many ways to store and organize data quickly and efficiently. It is one of the more useful data types available to any programming language.Arrays can most easily be described as an ordered list of elements. You can access the individual elements by referring to their index position within the array. The position is either specified numerically or by name.
Copy linkTweet thisAlerts:
@mahfoozauthorMar 11.2014 — thanks! this is what i was looking for. thanks again!
Copy linkTweet thisAlerts:
@NogDogMar 11.2014 — Another alternative might be to massage the array to dynamically add the "next" person to it:
[code=php]
<?php
$arr = Array
(
"pendingReview" => Array
(
"by" => "Rubab Admani",
"date" => "2014 - 01 - 08 12:03:45"
),

"pendingAssignment" => Array
(
"by" => "Farrukh Mushtaq",
"date" => "2014 - 01 - 08 16:11:21"
),

"inProgress" => Array
(
"by" => "Beatriz Artal",
"date" => "2014 - 01 - 08 16:48:27"
),

"finalReviewing" => Array
(
"by" => "Irfan Shafiq",
"date" => "2014 - 01 - 09 11:01:26"
),

"readyToSubmit" => Array
(
"by" => "Beatriz Artal",
"date" => "2014 - 01 - 09 13:37:26"
)

);

$keys = array_keys($arr);
foreach($keys as $ix => $key) {
if(isset($keys[$ix+1])) {
$arr[$key]['next'] = $arr[$keys[$ix+1]]['by'];
}
}
print_r($arr);
[/code]

Output:
<i>
</i>Array
(
[pendingReview] =&gt; Array
(
[by] =&gt; Rubab Admani
[date] =&gt; 2014 - 01 - 08 12:03:45
[next] =&gt; Farrukh Mushtaq
)

<i> </i>[pendingAssignment] =&gt; Array
<i> </i> (
<i> </i> [by] =&gt; Farrukh Mushtaq
<i> </i> [date] =&gt; 2014 - 01 - 08 16:11:21
<i> </i> [next] =&gt; Beatriz Artal
<i> </i> )

<i> </i>[inProgress] =&gt; Array
<i> </i> (
<i> </i> [by] =&gt; Beatriz Artal
<i> </i> [date] =&gt; 2014 - 01 - 08 16:48:27
<i> </i> [next] =&gt; Irfan Shafiq
<i> </i> )

<i> </i>[finalReviewing] =&gt; Array
<i> </i> (
<i> </i> [by] =&gt; Irfan Shafiq
<i> </i> [date] =&gt; 2014 - 01 - 09 11:01:26
<i> </i> [next] =&gt; Beatriz Artal
<i> </i> )

<i> </i>[readyToSubmit] =&gt; Array
<i> </i> (
<i> </i> [by] =&gt; Beatriz Artal
<i> </i> [date] =&gt; 2014 - 01 - 09 13:37:26
<i> </i> )

)
×

Success!

Help @mahfooz 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.19,
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,
)...