Skip to content

Tag: arrays

Apply function to every element of a multidimensional array

I have a multidimensional array like this (please ignore the strlen): And I want to call “strtoupper” for every element (Value1, Value2, etc.) on each level of the multidimensional array (document, etc.). I tried array_walk_recursive($array, “strtoupper”); but it doesn’t work. But why, what can I do? Answer As strtoupper does not change the original value, but returns new value instead,

How to remove static array after uncheck checkbox in jquery

I have two checkboxes, and I want whenever I click on any checkbox then their values (static array) should be inserted into “final” array (empty array). If I uncheck that checkbox then its value (static array) should be remove from “final array”. Right now I am inserting/pushing “static” array into blank array (final array), but I want to know that

How to check the key of next index of arrays in PHP?

I have an PHP array : I want to check the keys of each array and if not match need to add it on every array. Expecting output like: If the key is not exist need to add the key with value zero. Is that possible? I tried with array_key_exists() function… But I’m not sure where I want to check,

Convert an array to string using PHP

Still new in PHP and I am trying to convert an array to string in my code below: If I echo the $totalProfitsArray variable above i get this result: which is fine but i want to echo only the 44.35 value. So i tried to use the implode method like this: but still didn’t work and i get this error:

How to visit an array indexed by indexed in php / Laravel?

I got an API response like [“”,””,””] I got this array in a request variable $request->optional_email I am trying to access data by a loop like below: But it doesn’t work. How can I solve it? Answer As the $request->optional_email is just a list you do not need to use the $key variable in the foreach. Instead you should just

Merge every 2 arrays in a Multidimensional array PHP

So, this is a complicated question for me. Let’s say we have an array that goes like this: supposed to be FAQs question and answer are more than 1, the arrays above separates the faq question and faq answer in 2 different arrays and given that the array is a result of a 3rd party API (which you cannot control),