Categories
Code Area PHP Programming Tips and Tricks Tools and Technologies

Array Chunk based on Key Value in PHP

Sometimes programmer needs to chunk or grouping array based on the array key value. Look at the below code snippet, here I have a multidimensional array, and I want to group all same elements of each category.

OUTPUT:

array (
  'php' => 
  array (
    0 => 
    array (
      'category' => 'php',
      'post_id' => 100,
    ),
    1 => 
    array (
      'category' => 'php',
      'post_id' => 102,
    ),
    2 => 
    array (
      'category' => 'php',
      'post_id' => 104,
    ),
  ),
  'html' => 
  array (
    0 => 
    array (
      'category' => 'html',
      'post_id' => 101,
    ),
    1 => 
    array (
      'category' => 'html',
      'post_id' => 104,
    ),
  ),
  'js' => 
  array (
    0 => 
    array (
      'category' => 'js',
      'post_id' => 103,
    ),
  ),
)
Categories
Code Area PHP Tips and Tricks

Search Key Value Pair in Multidimensional Array

Are you Looking for key value search of a multidimensional array? This script will help you to search multidimensional array by key value pair.

You will get following output after executing this script.

Result:

Array
(
    [0] => Array
        (
            [name] => DDD
            [role] => agent
        )

    [1] => Array
        (
            [name] => EEE
            [role] => agent
        )

)
Categories
Code Area PHP

Array Difference in nth Level Recursively in PHP

Here I have written a code snippet for get array difference in nth lavel  recursively in php

Categories
Code Area PHP

How to Get Data Between Two Timestamps From an Array

Sometimes programmer/developer need to get data between two timestamps from multidimensional array . Here I have written some sort of code for getting data between two timestamps from multidimensional array. I hope that will be helpful for you!

 

Categories
Code Area PHP Programming

Search Value from Multi Dimension Array

Here is simple example of searching specific value from a multi dimension array.