This question already has answers here:
split a string into two based on a substring with all combinations
(2 answers)
Closed 7 months ago.
hello everyone i am getting value like Array ( [2] => FAB(CBY-DJ9)--9 ), i want two separate value like this FAB(CBY-DJ9) and 9 by loop, kindly help me i am a beginner.
hello everyone i am getting value like Array ( [2] => FAB(CBY-DJ9)--9 ), i want two separate value like this FAB(CBY-DJ9) and 9 by loop, kindly help me i am a beginner.hello everyone i am getting value like Array ( [2] => FAB(CBY-DJ9)--9 ), i want two separate value like this FAB(CBY-DJ9) and 9 by loop, kindly help me i am a beginner
With explode() you can seperate them.
$item = 'FAB(CBY-DJ9)--9';
list($code, $number) = explode('--', $item);
Related
This question already has answers here:
Get first key in a (possibly) associative array?
(25 answers)
Closed 2 years ago.
I have a multidimensional array and I want the first key that is
dynamic. How do I get that in PHP?
I want to display the customer name in frontend. But as you can see in the first
array there is the number [12345] => account number (the dynamic part). So if i
want to display customer name how can I get this with this dynamic
account number.
Array
(
[12345] => Array(
['customername'] => ABC
['customerid'] => 456
)
)
Try with Foreach
foreach($array as $value){
echo $value['customername'].'<br>';
echo $value['customerid'].'<br>';
}
This question already has answers here:
How can I add all of my array values together in PHP?
(4 answers)
Closed 3 years ago.
I have an array and I want to sum up the values of the array such as [0][1][2] and assign the result of the sum to a variable
My array
Array ( [0] => 1 [1] => 2 [2] => 0 )
Can anyone provide me a solution that would be really helpful?
Use php array_sum() function.
$val = array_sum($yourArray);
It will sum up all of your array elements into a variable.
This question already has answers here:
Better way to unset multiple array elements
(6 answers)
Closed 4 years ago.
I have an array of this form :
Array
(
[1] => A
[2] => B
[3] => C
)
I want to delete values where key = 1 and 2...
I have tried this
unset($array['1']);
unset($array['2']);
But I need to call 2 times unset... It's possible without 2 calls ?
Thanks, have a good day!
You can try like
$keyToRemove = array('1', '2');
foreach($keyToRemove as $key) {
unset($arr[$key]);
}
Also you can do it like this way too
$arr = array_diff_key($arr, array_flip($keyToRemove));
Similar answer you can check it here
This question already has answers here:
How to get single value from this multi-dimensional PHP array [duplicate]
(6 answers)
Closed 5 years ago.
I know this should be a relatively simple thing but I have not been able to do it yet. I have look hi and low and every example I try it fails I am sure it is fairly simple
Here is my array. I need to get the value of name last and filenames
Any help would be most appreciated.
Thanks!!
Array
(
[formData] => Array
(
[name] => TEST
[last] => TEST1
[filenames] => Array
(
[0] => /ocdata/uploads/export-1511887767.csv
)
)
)
Really simple method to see your content:
foreach($array as $k => $v)
{
echo $k . $v . PHP_EOL; // see content of your array
}
Or use directly the values:
$array['formData']['name'];
$array['formData']['last'];
$array['formData']['filenames'];
This question already has answers here:
How to combine two arrays together?
(3 answers)
Closed 6 years ago.
I am having two arrays like this
Array
(
[0] => username
[1] => avatar
)
Array
(
[0] => name
[1] => 4.jpg
)
Here, I need to get these values in the following format
'username'=>name,'avatar'=>4.jpg
i.e., merge the same key values in the above format..
How should I do this,..Someone help me..
If you think that my title is wrong,Please change it into correct format.
Thanks,
Use array_combine()
$final_array = array_combine($fist_array,$second_array);
Reference:- http://php.net/manual/en/function.array-combine.php
use $c = array_combine($a, $b);