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] =>
)
}
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);
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);
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);
$rated = array();
foreach($yourArr as $arr) {
if($arr['related_user'] == 1) {
$rated[] = $arr;
}
}
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>";
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;