1

I have an array in multidimensional, which i want to get the array set only match my specific value, right now i have a column call related_users, I need a statement that will get this array values only when is this array's related_user value is 1.

Array
(
[0] => Array
    (
        [id] => 1
        [advertiser] => Hairvolution
        [postdate] => 
        [campaign_period] => 
        [related_users] => 1
        [reporting_period] => 
        [Delivered Impressions] => 1439763
        [Clicks] => 4124
        [Click-Through Rate] => 0.29
    )

[1] => Array
    (
        [id] => 4
        [advertiser] => 
        [postdate] => 
        [campaign_period] => 
        [related_users] => 2
        [reporting_period] => 
        [Delivered Impressions] => 
        [Clicks] => 
        [Click-Through Rate] => 
    )

[2] => Array
    (
        [id] => 7
        [advertiser] => maxlibin
        [postdate] => 
        [campaign_period] => 
        [related_users] => 2
        [reporting_period] => 
        [Delivered Impressions] => 
        [Clicks] => 
        [Click-Through Rate] => 
    )
 [3] => Array
    (
        [id] => 8
        [advertiser] => maxlibin
        [postdate] => 
        [campaign_period] => 
        [related_users] => 1
        [reporting_period] => 
        [Delivered Impressions] => 
        [Clicks] => 
        [Click-Through Rate] => 
    )

[4] => Array
    (
        [id] => 9
        [advertiser] => maxlibin
        [postdate] => 
        [campaign_period] => 
        [related_users] => 1
        [reporting_period] => 
        [Delivered Impressions] => 
        [Clicks] => 
        [Click-Through Rate] => 
    )
}
2
  • 1
    Instead of saying "I need a statement", better tell us what you have tried. Commented Apr 24, 2013 at 5:22
  • Can you give an example of "i want to get the array set only match my specific value" ? Commented Apr 24, 2013 at 5:24

6 Answers 6

1

Use for loop and iterate it and check the related_users value ,if it matches 1 then append the array to new array.

$arr = array();
for($i=0;$i< count($your_array);$i++) {
    if($your_array[$i]['related_users'] == 1) {
        $arr[] = $your_array[$i];
    }
}
print_r($arr);
Sign up to request clarification or add additional context in comments.

Comments

0

I am not sure, what you want, but you can try this code:

$final = array();
    foreach($arrayName as $arrayItem){
        if ($arrayItem['related_user'] == 1){
            $final[] = $arrayItem;
        }
    }
var_dump($final);

Comments

0
$rated = array();
foreach($yourArr as $arr) {
    if($arr['related_user'] == 1) {
        $rated[] = $arr;
    }
}

Comments

0

use foreach for array that easy way to iterate over arrays and check the related_users value ,if it is 1 then append to the new array $result.

$result = array();
foreach($your_array as $Item){
  if ($Item['related_user'] == 1){
     $result[] = $Item;
  }
}
print_r($result);

Comments

0

Use this

                $array=YourArray;
            $result=array();
            foreach($array as $a) {

                if($a['related_users']==1){
                    $result=$a;
                }

            }

            echo "Resultant Array =";
            echo "<pre>";
                print_r($result);
            echo "</pre>";

Comments

0
    function get_specific_arr_set($array) {

      $arr_final = array();
      if (!empty($array)) {

        foreach ($array as $item) {

            if ($item['related_users'] == 1) {

                $arr_final[] = $item; 
            }
        }
      }

      return $arr_final;
    }

$result = get_specific_arr_set($your_arr);

echo "<pre>";print_r($result);echo "</pre>";exit;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.