-1

I have an array like the code bellow:

Array ( [Row] => Array ( [0] => Array ( [PIN] => 269 [DateTime] => 2019-04-03 00:00:10 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [1] => Array ( [PIN] => 56 [DateTime] => 2019-04-03 00:00:33 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [2] => Array ( [PIN] => 99 [DateTime] => 2019-04-03 00:00:46 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [3] => Array ( [PIN] => 99 [DateTime] => 2019-04-03 00:00:49 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [4] => Array ( [PIN] => 213 [DateTime] => 2019-04-03 00:01:02 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [5] => Array ( [PIN] => 193 [DateTime] => 2019-04-03 00:01:06 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [6] => Array ( [PIN] => 271 [DateTime] => 2019-04-03 00:04:43 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [7] => Array ( [PIN] => 271 [DateTime] => 2019-04-03 00:04:52 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [8] => Array ( [PIN] => 54 [DateTime] => 2019-04-03 00:04:56 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [9] => Array ( [PIN] => 247 [DateTime] => 2019-04-03 00:07:22 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [10] => Array ( [PIN] => 225 [DateTime] => 2019-04-03 00:17:07 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [11] => Array ( [PIN] => 375 [DateTime] => 2019-04-03 00:48:06 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [12] => Array ( [PIN] => 273 [DateTime] => 2019-04-03 01:03:47 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [13] => Array ( [PIN] => 273 [DateTime] => 2019-04-03 01:03:50 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [14] => Array ( [PIN] => 282 [DateTime] => 2019-04-03 01:15:52 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [15] => Array ( [PIN] => 362 [DateTime] => 2019-04-03 01:26:02 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [16] => Array ( [PIN] => 196 [DateTime] => 2019-04-03 01:26:06 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [17] => Array ( [PIN] => 52 [DateTime] => 2019-04-03 01:26:46 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [18] => Array ( [PIN] => 32 [DateTime] => 2019-04-03 01:26:59 [Verified] => 0 [Status] => 0 [WorkCode] => 0 ) [19] => Array ( [PIN] => 362 [DateTime] => 2019-04-03 01:27:10 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [20] => Array ( [PIN] => 32 [DateTime] => 2019-04-03 01:27:20 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [21] => Array ( [PIN] => 52 [DateTime] => 2019-04-03 01:27:24 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [22] => Array ( [PIN] => 176 [DateTime] => 2019-04-03 03:00:40 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [23] => Array ( [PIN] => 176 [DateTime] => 2019-04-03 03:00:44 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [24] => Array ( [PIN] => 182 [DateTime] => 2019-04-03 03:01:02 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [25] => Array ( [PIN] => 226 [DateTime] => 2019-04-03 03:01:41 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [26] => Array ( [PIN] => 226 [DateTime] => 2019-04-03 03:01:45 [Verified] => 0 [Status] => 1 [WorkCode] => 0 ) [27] => Array ( [PIN] => 175 [DateTime] => 2019-04-03 06:39:54 [Verified] => 0 [Status] => 0 [WorkCode] => 0 ) [28] => Array ( [PIN] => 313 [DateTime] => 2019-04-03 06:41:36 [Verified] => 0 [Status] => 0 [WorkCode] => 0 ) [29] => Array ( [PIN] => 206 [DateTime] => 2019-04-03 06:43:44 [Verified] => 0 [Status] => 0 [WorkCode] => 0 ) [30] => Array ( [PIN] => 305 [DateTime] => 2019-04-03 06:55:23 [Verified] => 0 [Status] => 0 [WorkCode] => 0 ) ) )

I want to get only the PIN numbers

Yassine CHABLI
  • 3,459
  • 2
  • 23
  • 43
NOOB
  • 33
  • 6

1 Answers1

0

just loop the array like this way :

foreach($data['Row'] as $item){ // $data is the array that contain all data
  echo $item['PIN'];
}

if you want to store those pin numbers into an array :

 $pins = array();
foreach($data['Row'] as $item){
  $pins[]=$item['PIN'];
}
var_dump($pins); // that will show an array of pins [269,99,...]

If you want to convert the $pins array to json :

$pins_json= json_encode($pins,true);
Yassine CHABLI
  • 3,459
  • 2
  • 23
  • 43
  • Invalid argument supplied for foreach() – NOOB Apr 02 '19 at 23:17
  • what's the name of variable contain the whole data ? don't copy-paste code, you have to modify the name of variable $data . may be you are namming it somehow different to $data – Yassine CHABLI Apr 02 '19 at 23:18
  • $tad_factory = new TADPHP\TADFactory(); $comands = TAD::commands_available(); $info =array(); $IP = '203.177.160.230'; $b1 = (new TADFactory(['ip'=>'127.0.0.1']))->get_instance(); $att_logs = $b1->get_att_log(); $filtered_att_logs = $att_logs->filter_by_date( ['start' => '2019-04-03','end' => '2019-04-03'] ); $logs = $filtered_att_logs->to_array(); foreach($logs['row'] as $item){ // $data is the array that contain all data echo $item['PIN']; } – NOOB Apr 02 '19 at 23:19
  • delete 'row' from $logs i mean , foreach($logs as $item){ – Yassine CHABLI Apr 02 '19 at 23:22
  • Undefined index: PIN – NOOB Apr 02 '19 at 23:25
  • sorry , make Row instead of row – Yassine CHABLI Apr 02 '19 at 23:29
  • Its ok now. but i need to convert it to json format and fetch the data. – NOOB Apr 02 '19 at 23:34
  • i don't really understand that point ? can you explain , you said that you want to extract only the pins , and what do you want to convert to json , the array of pins or something else ? – Yassine CHABLI Apr 02 '19 at 23:37
  • the first problem is solve but . the out put is this 26956999921319327127154247225375273273282362196523236232521761761822262261753132063052012341891898238811037437 . which is the pins but I need to insert each pins not this compressed numbers of pins. – NOOB Apr 02 '19 at 23:40
  • try the second snnipet not the first, in the second one i'm storing pins into an array . check the second code snippet – Yassine CHABLI Apr 02 '19 at 23:42
  • Thank you sir its ok now :D – NOOB Apr 02 '19 at 23:46
  • use json_encode if you want to convert the array of pins to json format . – Yassine CHABLI Apr 02 '19 at 23:47
  • enjoy the great PHP – Yassine CHABLI Apr 02 '19 at 23:47