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
The str_split() function splits a string into an array.
The explode() function breaks a string into an array. Note: The "separator" parameter cannot be an empty string. Note: This function is binary-safe.
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.
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.
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']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With