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,
Tag: arrays
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
Find a a value in a multidimentional array, and return a value from the same array
I’m trying to find a value in a milti array’s array, and after finding it, I want to return a different key, not sure how to explain it further. I have an array: I’m trying to find the array by [custom_tab_field_id], and return the current’s array [status]. I created a function that should do just that, but it’s always returning
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,
MongoDB & PHP | How to add into object that is inside an array?
I am new to MongoDB and PHP and I am trying to make an API. The current problem I have is that I am not able to add an array into an object that is inside an array (of objects). I have tried a lot, but all failed. This is the document I have so far: I would like to
Print Multi-dimensional array using loop in PHP
I don’t understand how to use nested loops(for, foreach,while,dowhile) for printing this multi-dimensional array values in separate lines. I am new in this sector. Here is the code: Answer you have associative array inside associative array You have to loop the first associative array and inside it loop the associative array like this
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:
Zip multiple arrays in PHP based on their identical keys and not their indices or their positions in array
I have two arrays: note that in $b Array ‘three’ and ‘two’ keys are not in same order as $a. also ‘six’ key is not available in $b Array. I want this result as output: I tried to use array_map but it don’t detect keys and just zip them based of their indices: Answer Can’t you just use ksort(). Then,
How to visit an array indexed by indexed in php / Laravel?
I got an API response like [“at123@gmail.com”,”adhd5@gmail.com”,”adahsad5@gmail.com”] 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),