PHP array formatting

I have the following PHP array

JobNo: 15-001:001
TaskNo: 15-001:001
Hours: 2

JobNo: 15-002:002
TaskNo: 15-002:002
Hours: 3

and so on.  I want to convert the values in the JobNo field to only keep everything left of the colon (ie 15-001) and for the TaskNo field only keep everything right of the colon (ie 001).  The resulting array would be:

JobNo: 15-001
TaskNo: 001
Hours: 2

JobNo: 15-002
TaskNo: 002
Hours: 3

Current array is in PHP and would like the conversion to happen on the PHP side.  Thanks!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Something like this.  The numbers represent the positions in the sub-arrays.
foreach($array as $val) {
$JobNo = explode(':',$val[0]);
echo $JobNo[0];
$TaskNo = explode(':',$val[1]);
echo $TaskNo[1];
echo $val[2];

Open in new window

More info:
Dan CraciunIT ConsultantCommented:
Don't you need an "&" to modify the array inside the loop?

foreach ($yourarray as &$row){
  $job = explode(":", $row["JobNo"]);
  $row["JobNo"] = $job[0];
  $task = explode(":", $row["TaskNo"]);
  $row["TaskNo"] = $task[0];

Open in new window

Marco GasiFreelancerCommented:
See if this makes sense to you:
$jobs = array(
				"JobNo" => "15-001:001",
				"TaskNo" => "15-001:001",
				"Hours" => "2"
				"JobNo" => "15-002:002",
				"TaskNo" => "15-002:002",
				"Hours" => "3"

$final_jpbs = array();
foreach($jobs as $job)
//	$final_jobs[] = array();
	$values = explode(':', $job['JobNo']);
	$final_jobs[] = array(
			"JobNo" => $values[0],
			"TaskNo" => $values[1],
			"Hours" => $job['Hours']
echo "<pre>";
echo "</pre>";

Open in new window

Dan CraciunIT ConsultantCommented:
Yup. Marco is right. I have not read the question properly.
foreach ($yourarray as &$row){
  $job = explode(":", $row["JobNo"]);
  $row["JobNo"] = $job[0];
  $row["TaskNo"] = $job[1];

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.