Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to separate array after and before dot php

Tags:

php

I have an array like this :

Array (
[0] => Array (
[tsk_hours_spent] => 23425.00
)
[1] => Array (
[tsk_hours_spent] => 2.00
)
[2] => Array (
[tsk_hours_spent] => 0.00
)
[3] => Array (
[tsk_hours_spent] => 0.00
)
[4] => Array (
[tsk_hours_spent] => 0.20
)
)

I want results seperated based on '.' into two array

ie.,

Before dot one array and after dot one array eg:

First array will be : 23425,2,0,0,0

Second array will be : 00,00,00,00,20

like image 378
vignesh.D Avatar asked Mar 15 '14 08:03

vignesh.D


People also ask

How can I split a string into two parts in PHP?

The str_split() function splits a string into an array.

What does explode () do in PHP?

The explode() function breaks a string into an array. Note: The "separator" parameter cannot be an empty string. Note: This function is binary-safe.

How do I separate comma separated values in PHP?

Use explode() or preg_split() function to split the string in php with given delimiter. PHP | explode() Function: The explode() function is an inbuilt function in PHP which is used to split a string in different strings.

How split a string after a specific character in PHP?

explode() is a built in function in PHP used to split a string in different strings. The explode() function splits a string based on a string delimiter, i.e. it splits the string wherever the delimiter character occurs. This functions returns an array containing the strings formed by splitting the original string.


1 Answers

Try This

<?php
$tsk_hours_spent = array(array('tsk_hours_spent'=>'23425.00'),array('tsk_hours_spent'=>'2.00'),array('tsk_hours_spent'=>'0.00'),array('tsk_hours_spent'=>'0.00'),array('tsk_hours_spent'=>'0.00'));

$finalArray = array();
foreach($tsk_hours_spent as $key){

        $tmp = (explode('.',$key['tsk_hours_spent']));
        $finalArray['partOne'][] = $tmp[0];
        $finalArray['partSecond'][] = $tmp[1];

}
echo implode(',',$finalArray['partOne']);
echo "</br>";
echo implode(',',$finalArray['partSecond']);
like image 163
sismaster Avatar answered Sep 26 '22 18:09

sismaster