Skip to content
Advertisement

Tag: arrays

How to find value?

I make this associative array with PHP. Now by using array_rand() function => The Output is: [0] => a [1] => b This output shows me only the key of the array. But I want to see the value too. How can I find the value of this array using array_rand()? Answer Use the keys to access the original array

Combine neighbouring elemets to new array of min 2

I have a quite specific problem. I want to combine every element of an array with neighboring elements to a new array of minimum length 2. Im not sure if Im explaining that correctly so here’s an example: Given the array: I want to create a new array that looks like this: [‘abcd’] is not returned since it is only

php find item dimension in array

find items level(depth) in array; hi im new in php and i cant find any method to find what dimension array items are in. for example: the array above has key named email and the email key is in second level of the array. is there any function or method or way to find this level. I found a method

Sort an array so that a given value would be the first

I would like to sort the array so that if a given value ($first_in_array) = ‘brand’ value, the array would become the first it the queue. In the given example an array with index[1] should appear like at index[0]. Answer You can use the callback function of usort and first deal with the case where exactly one of the two

PHP – Show Array as HTML Table

I have this code which pulls an array of IP and MAC addresses from my server. <?php $arpa = shell_exec('arp -a'); $arpa = stristr($arpa, 'Type'); $arpa = preg_replace("/s+/", " &…

Get dependencies Ids Algorithm

I have this problem and I came out with a solution but what is the best way to solve this problem ? Thank you in advance. Given an array of strings and an array of tasks you need to return a sorted array with tasks and dependencies tasks ids. Example: Expected output: So far this is the solution I built,

Correct PHP syntax for array that contains associative arrays

I need an array with entries for different industries then inside that different professions then inside that headings for different attributes such as “knowledge”, “skills”, “abilities”. Then entries under each heading. This page gives an example of one entry: Picker and Packer Here is the code for the associative array I have so far. I am surprised I had to

Advertisement