Click here to Skip to main content
15,888,003 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have the following Array:

[{"is_disable": false, "canbus_id": "", "daily_mileage": "79.91", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "238822.9094", "temp_min": 0, "sim_number": "89490200001222280318", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 0, "gsm_number": "76140169", "beacon_id": 357454070966716, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "07224812", "type": 75, "price": "13.90", "added_by": 30, "latest_signal_id": 11355797905, "gsm_areacode": "0151", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 11295768204, "trip_status": 0, "added_at": "2016-08-11 17:12:48", "device_id": 1000016558, "name": "100", "transmission": "94.4678427307", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2020-07-06 16:55:15"}, {"is_disable": false, "canbus_id": "", "daily_mileage": "150.67", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "225937.487", "temp_min": 0, "sim_number": "89490200001222287305", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 0, "gsm_number": "76098470", "beacon_id": 356173068452528, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "06652243", "type": 120, "price": "13.90", "added_by": 30, "latest_signal_id": 11355887514, "gsm_areacode": "0151", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 11295798931, "trip_status": 0, "added_at": "2016-07-18 13:17:22", "device_id": 1000014684, "name": "101", "transmission": "104.754475821", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2020-07-06 17:10:47"}, {"is_disable": false, "canbus_id": "", "daily_mileage": "0.00", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "0.0", "temp_min": 0, "sim_number": "89490200001222280326", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 0, "gsm_number": "76140180", "beacon_id": 357454070966583, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "07224827", "type": 75, "price": "13.90", "added_by": 30, "latest_signal_id": 4750866162, "gsm_areacode": "0151", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 4750866162, "trip_status": 0, "added_at": "2016-08-11 17:13:14", "device_id": 1000016559, "name": "102", "transmission": "0.00440216064456", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2016-10-14 13:55:18"}, {"is_disable": false, "canbus_id": "", "daily_mileage": "0.07", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "128979.53", "temp_min": 0, "sim_number": "89490200001222287297", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 0, "gsm_number": "76098477", "beacon_id": 356173068339048, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "06651413", "type": 75, "price": "13.90", "added_by": 30, "latest_signal_id": 11355870182, "gsm_areacode": "0151", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 11295786522, "trip_status": 0, "added_at": "2016-07-18 13:17:43", "device_id": 1000014686, "name": "103", "transmission": "48.0815112933", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2020-07-06 17:07:45"}, {"is_disable": false, "canbus_id": "", "daily_mileage": "70.99", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "254239.5951", "temp_min": 0, "sim_number": "89490200001222280359", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 0, "gsm_number": "76140179", "beacon_id": 357454070716954, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "07224797", "type": 79, "price": "13.90", "added_by": 30, "latest_signal_id": 11355918544, "gsm_areacode": "0151", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 11295758804, "trip_status": 0, "added_at": "2016-08-11 17:14:07", "device_id": 1000016562, "name": "104", "transmission": "96.7045163633", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2020-07-06 17:16:23"}, {"is_disable": false, "canbus_id": "", "daily_mileage": "21.90", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "304073.034", "temp_min": 0, "sim_number": "89490200001222287578", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 0, "gsm_number": "76139406", "beacon_id": 357454070965718, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "07224814", "type": 120, "price": "13.90", "added_by": 30, "latest_signal_id": 11355847968, "gsm_areacode": "0151", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 11295842023, "trip_status": 0, "added_at": "2016-08-11 17:15:00", "device_id": 1000016565, "name": "105", "transmission": "143.196938239", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2020-07-06 17:03:52"}, {"is_disable": false, "canbus_id": "", "daily_mileage": "0.01", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "165283.731", "temp_min": 0, "sim_number": "89490200001222280342", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 0, "gsm_number": "76140192", "beacon_id": 357454070969520, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "07224692", "type": 79, "price": "13.90", "added_by": 30, "latest_signal_id": 11355852062, "gsm_areacode": "0151", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 11295781428, "trip_status": 0, "added_at": "2016-08-11 17:13:40", "device_id": 1000016561, "name": "106", "transmission": "70.0273424265", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2020-07-06 17:04:36"}, {"is_disable": false, "canbus_id": "", "daily_mileage": "0.20", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "266959.607", "temp_min": 0, "sim_number": "89490200001222287313", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 0, "gsm_number": "76098469", "beacon_id": 356173068153878, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "06651372", "type": 120, "price": "13.90", "added_by": 30, "latest_signal_id": 11355874474, "gsm_areacode": "0151", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 11295834810, "trip_status": 0, "added_at": "2016-07-18 13:17:31", "device_id": 1000014685, "name": "107", "transmission": "115.902919835", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2020-07-06 17:08:30"}, {"is_disable": false, "canbus_id": "", "daily_mileage": "195.53", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "161626.859", "temp_min": 0, "sim_number": "89490200001222287552", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 0, "gsm_number": "76139402", "beacon_id": 357454070915093, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "07224580", "type": 120, "price": "13.90", "added_by": 30, "latest_signal_id": 11355921729, "gsm_areacode": "0151", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 11295784845, "trip_status": 0, "added_at": "2016-08-11 17:15:28", "device_id": 1000016567, "name": "108", "transmission": "73.3666257757", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2020-07-06 17:16:56"}, {"is_disable": false, "canbus_id": "", "daily_mileage": "184.19", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "279374.912", "temp_min": 0, "sim_number": "89490200001222280300", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 0, "gsm_number": "76140165", "beacon_id": 357454070970668, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "07224690", "type": 120, "price": "13.90", "added_by": 30, "latest_signal_id": 11355917436, "gsm_areacode": "0151", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 11295736315, "trip_status": 0, "added_at": "2016-08-11 17:12:33", "device_id": 1000016557, "name": "109", "transmission": "124.144438329", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2020-07-06 17:16:11"}, {"is_disable": false, "canbus_id": "", "daily_mileage": "177.45", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "295268.3739", "temp_min": 0, "sim_number": "89490200001222280367", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 0, "gsm_number": "76140191", "beacon_id": 357454070716905, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "07224790", "type": 120, "price": "13.90", "added_by": 30, "latest_signal_id": 11355884005, "gsm_areacode": "0151", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 11295677707, "trip_status": 0, "added_at": "2016-08-11 17:14:29", "device_id": 1000016563, "name": "110", "transmission": "128.90077938", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2020-07-06 17:10:11"}, {"is_disable": false, "canbus_id": "", "daily_mileage": "32.75", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "259966.202", "temp_min": 0, "sim_number": "89490200001222287537", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 0, "gsm_number": "76139386", "beacon_id": 357454070967342, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "07224668", "type": 120, "price": "13.90", "added_by": 30, "latest_signal_id": 11353333075, "gsm_areacode": "0151", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 11295377119, "trip_status": 0, "added_at": "2016-08-11 17:14:44", "device_id": 1000016564, "name": "111", "transmission": "117.01760193", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2020-07-06 11:16:43"}, {"is_disable": false, "canbus_id": "", "daily_mileage": "5.18", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "123291.79", "temp_min": 0, "sim_number": "89490200001222280334", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 0, "gsm_number": "76140174", "beacon_id": 357454071042285, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "07224706", "type": 79, "price": "13.90", "added_by": 30, "latest_signal_id": 11355900678, "gsm_areacode": "0151", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 11295826697, "trip_status": 0, "added_at": "2016-08-11 17:13:28", "device_id": 1000016560, "name": "115", "transmission": "59.4283460756", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2020-07-06 17:13:10"}, {"is_disable": false, "canbus_id": "", "daily_mileage": "95.18", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "8248.518", "temp_min": 0, "sim_number": "89430103119128000590", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 30, "gsm_number": "873640059", "beacon_id": 356173068704688, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "06652294", "type": 79, "price": "13.90", "added_by": 67, "latest_signal_id": 11355778714, "gsm_areacode": "43688", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 11295706585, "trip_status": 0, "added_at": "2019-12-19 14:46:10", "device_id": 1000075422, "name": "116", "transmission": "3.34102061169", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2020-07-06 16:52:07"}]
I want to grab the "latest_signal_id" from the given "device_id". How to do this?

Thanks for your help

What I have tried:

Searched in google but dont get solved the problem
Posted
Updated 6-Jul-20 21:19pm

This should provide you some inspiration; I shortened your array and have put it inside SINGLE quotes in the first line:

	$json=
'[{"is_disable": false, "canbus_id": "", "daily_mileage": "79.91", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "238822.9094", "temp_min": 0, "sim_number": "89490200001222280318", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 0, "gsm_number": "76140169", "beacon_id": 357454070966716, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "07224812", "type": 75, "price": "13.90", "added_by": 30, "latest_signal_id": 11355797905, "gsm_areacode": "0151", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 11295768204, "trip_status": 0, "added_at": "2016-08-11 17:12:48", "device_id": 1000016558, "name": "100", "transmission": "94.4678427307", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2020-07-06 16:55:15"}, {"is_disable": false, "canbus_id": "", "daily_mileage": "150.67", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "225937.487", "temp_min": 0, "sim_number": "89490200001222287305", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 0, "gsm_number": "76098470", "beacon_id": 356173068452528, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "06652243", "type": 120, "price": "13.90", "added_by": 30, "latest_signal_id": 11355887514, "gsm_areacode": "0151", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 11295798931, "trip_status": 0, "added_at": "2016-07-18 13:17:22", "device_id": 1000014684, "name": "101", "transmission": "104.754475821", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2020-07-06 17:10:47"}, {"is_disable": false, "canbus_id": "", "daily_mileage": "0.00", "command_internal_number": "", "tank_height": "0", "immobilizer_status": 0, "garmin_check_driver": 0, "velocity_info": 0, "latest_mileage": "0.0", "temp_min": 0, "sim_number": "89490200001222280326", "canbus_serial": "", "deleted_at": "None", "sap_status": 1, "user_id": 152620, "latest_engine_hour": 0, "tank_capacity": null, "temp_max": 0, "gsm_number": "76140180", "beacon_id": 357454070966583, "note": "", "canbus_program_nr": "", "activation": 0, "car_state": "", "serial_number": "07224827", "type": 75, "price": "13.90", "added_by": 30, "latest_signal_id": 4750866162, "gsm_areacode": "0151", "tank_capacity_lt": 0, "latest_zone_id": -1, "hide_status": false, "latest_geofence_signal_id": 4750866162, "trip_status": 0, "added_at": "2016-08-11 17:13:14", "device_id": 1000016559, "name": "102", "transmission": "0.00440216064456", "box_type": 22, "start_date": "None", "latest_task_record_id": 0, "command_password": "", "canbus_type": "", "latest_geocode_sent_at": "2016-10-14 13:55:18"}]';
	
	$arr=json_decode($json);
	
	foreach($arr as $obj) {
		$device_id = $obj->device_id;
		$latest_signal_id = $obj->latest_signal_id;
		echo "<p>$device_id = $latest_signal_id</p>";
	}


It generates

1000016558 = 11355797905

1000014684 = 11355887514

1000016559 = 4750866162


and that should get you started.
 
Share this answer
 
Comments
Fynn Pfingsten 7-Jul-20 5:33am    
Hello Thanks! It is working. I have another question, i have another array which has no "[" tag at the beginning. It startet directly with "{". The problem is the result is a lot of "=" tags.
Luc Pattyn 7-Jul-20 11:02am    
This was your fifth question.
Each and every time "what I have tried" was answered by something along the line of "Searched in google but didn't find a solution to the problem"

You show no code, no error messages, nothing. No sign of you really trying anything.

And now, you tell me the code I gave you, or some variant thereof, "works". What I want to hear is you did some research and now understand why and how it works. Then you would have made some progress, and be better prepared to answer your own questions...


If you are new to programming, or new to a language or some specific aspect of software, then start by reading some chapters in a book on the subject. Make an effort, try to learn. We are not here to spoon feed you.

Good luck.
Fynn Pfingsten 7-Jul-20 11:10am    
Thanks for your answer! Google or other platforms not give me an answer. Tanks a lot for your code, you helped me a lot. and i tryed to solve the problem by myself with the new array but dont get it. because [ is missing at the beginning and i dont know how decode of an array works. so can you help me or not?
Luc Pattyn 7-Jul-20 11:13am    
Why do you insist on calling it an array, you said yourself it did not start with a bracket.
Do you know at all what JSON is? did you read the documentation on json_decode?
do some research, till you do I will not answer anymore.
Fynn Pfingsten 7-Jul-20 11:18am    
$json2=
'{"canbus_engine_temp": "", "signal_id": 11354658214, "input_2_voltage": 0.0, "canbus_doors": "", "nr_sat": 18, "signal_strenght": 12, "canbus_fuel_consumption": "", "beacon_id": 356173068452528, "input_6": 0, "input_7": 0, "input_4": 0, "input_5": 0, "input_2": 0, "input_3": 0, "input_0": 0, "input_1": 0, "canbus_total_driving_time": "", "dec_long": 9, "canbus_fuel_level_pr": "", "mileage": 225937.4844, "canbus_lights": "", "canbus_device_state": "", "canbus_total_engine_hours": "", "canbus_fuel_level_lt": "", "canbus_total_fuel_used": "", "dec_lat": 52, "input_1_voltage": 12.7, "speed_km": 0.0, "canbus_info_indicators": "", "geocode_sent_at": "2020/07/06 14:10:47", "added_at": "2020-07-06 14:10:51", "signal_mode": 2, "canbus_fuel_range": "", "canbus_total_idle_fuel_use": "", "signal_type": 4, "canbus_engine_rpm": ""}';

$arr2=json_decode($json2);

foreach($arr2 as $obj2) {
$device_id2 = $obj2->dec_long;
$latest_signal_id2 = $obj2->dec_lat;
echo "$device_id2 = $latest_signal_id2";
}
There are many id's in your array, so not sure which one you are referring to.

Also, you did not mention where the array is stored, in session or other place?

To call a key and value of an array -
PHP
$myArray = $_SESSION['theIDname'];
echo $myArray;


Also not mentioning if you want all the array id's or just a certain one, loop through or not.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900