使用rest想要显示有关项目的详细信息,但是功能代码中有一个错误但是根据我的说法是对的但是第7行有错误。我有两个代码如下 的index.php
<?php
header("content-Type:application/json");
include("function.php");
if(!empty($_GET['name'])){
$name = $_GET['name'];
$price = get_price($name);
if(empty($price))
deliver_response(200,"book not found",NULL);
else
deliver_response(200,"book found",price);
}
else{
deliver_response(400,"invalid",NULL);
}
function deliver_response($status,$status_message,$data)
{
header("HTTP/1.1 $status $status_message");
$response['status']=$status;
$response['status_message']=$status_message;
$response['data']=$data;
$json_response=json_encode($response);
echo $json_response;
}
?>
功能代码
<?php
function get_price($find)
{
$books = array(
"java" => 300,
"c" => 250,
"php" => 350);
for($books as $book => $price) {
if($books == $find) {
return $price;
break;
}
}
}
?>
答案 0 :(得分:2)
您需要在此处进行更改,将books
更改为book
if($book==$find)
{
return $price;
break;
}
同时更改foreach
而不是for
其foreach
语法检查本手册:http://php.net/manual/en/control-structures.foreach.php
答案 1 :(得分:2)
您需要使用IsExpanded
循环,而不是foreach
循环。而且你不需要休息,因为它永远不会到达它。此外,循环内的for
需要books
,否则您要与数组进行比较,而不是键。
book
答案 2 :(得分:1)
在if语句中使用foreach循环而不是for循环和$ book而不是$ books。
07-14 12:24:21.820 25368-25368/vertex2016.mvjce.edu.bluealert I/System.out: #####THIS IS BEFORE SOCKET CONNECT#####
07-14 12:24:21.820 25368-25368/vertex2016.mvjce.edu.bluealert W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
07-14 12:24:21.824 25623-25652/? D/BTIF_SOCK: service_uuid: 00001101-0000-1000-8000-00805f9b34fb
07-14 12:24:21.824 25623-25662/? W/bt-l2cap: L2CA_ErtmConnectReq() PSM: 0x0001 BDA: b01041928d1e p_ertm_info: 0x00000000 allowed:0x0 preferred:0
07-14 12:24:21.824 781-1154/? E/AudioTrack: AudioTrack::set : Exit
07-14 12:24:21.836 295-923/? D/audio_hw_primary: start_output_stream: enter: stream(0xab02e8e8)usecase(1: low-latency-playback) devices(0x2)
07-14 12:24:21.836 295-923/? D/audio_hw_primary: select_devices: out_snd_device(2: speaker) in_snd_device(0: )
07-14 12:24:21.836 295-923/? W/msm8916_platform: Codec backend bitwidth 16, samplerate 48000
07-14 12:24:21.836 295-923/? D/hardware_info: hw_info_append_hw_type : device_name = speaker
07-14 12:24:21.842 295-923/? W/audio_hw_utils: audio_extn_utils_update_stream_app_type_cfg: App type could not be selected. Falling back to default
07-14 12:24:21.842 295-923/? I/audio_hw_primary: select_devices Selected apptype: 69936
07-14 12:24:21.842 295-923/? D/ACDB-LOADER: ACDB -> send_audio_cal, acdb_id = 15, path = 0
07-14 12:24:21.842 295-923/? D/ACDB-LOADER: ACDB -> send_asm_topology
07-14 12:24:21.842 295-923/? D/ACDB-LOADER: ACDB -> ACDB_CMD_GET_AUDPROC_STREAM_TOPOLOGY_ID
07-14 12:24:21.842 295-923/? D/ACDB-LOADER: ACDB -> send_adm_topology
07-14 12:24:21.842 295-923/? D/ACDB-LOADER: ACDB -> ACDB_CMD_GET_AUDPROC_COMMON_TOPOLOGY_ID
07-14 12:24:21.842 295-923/? D/ACDB-LOADER: ACDB -> send_audtable
07-14 12:24:21.842 295-923/? D/ACDB-LOADER: ACDB -> ACDB_CMD_GET_AUDPROC_COMMON_TABLE
07-14 12:24:21.842 295-923/? D/ACDB-LOADER: ACDB -> AUDIO_SET_AUDPROC_CAL
07-14 12:24:21.842 295-923/? D/ACDB-LOADER: ACDB -> send_audvoltable
07-14 12:24:21.842 295-923/? D/ACDB-LOADER: ACDB -> ACDB_CMD_GET_AUDPROC_GAIN_DEP_STEP_TABLE
07-14 12:24:21.842 295-923/? D/ACDB-LOADER: ACDB -> AUDIO_SET_AUDPROC_VOL_CAL
07-14 12:24:21.842 295-923/? D/ACDB-LOADER: ACDB -> send_afe_cal
07-14 12:24:21.842 295-923/? D/ACDB-LOADER: ACDB -> ACDB_CMD_GET_AFE_COMMON_TABLE
07-14 12:24:21.842 295-923/? D/ACDB-LOADER: ACDB -> AUDIO_SET_AFE_CAL
07-14 12:24:21.842 295-923/? D/ACDB-LOADER: ACDB -> send_hw_delay : acdb_id = 15 path = 0
07-14 12:24:21.842 295-923/? D/ACDB-LOADER: ACDB -> ACDB_AVSYNC_INFO: ACDB_CMD_GET_DEVICE_PROPERTY
07-14 12:24:21.843 295-923/? I/audio_hw_utils: audio_extn_utils_send_app_type_cfg app_type 69936, acdb_dev_id 15, sample_rate 48000
07-14 12:24:21.844 295-923/? D/audio_hw_primary: select_devices: done
07-14 12:24:22.758 25623-25662/? W/bt-btm: btm_acl_role_changed: BDA: b0-10-41-92-8d-1e
07-14 12:24:22.758 25623-25662/? W/bt-btm: btm_acl_role_changed: New role: 0
07-14 12:24:22.876 25623-25662/? W/bt-btm: btm_acl_created hci_handle=2 link_role=1 transport=1
07-14 12:24:22.876 25623-25662/? W/bt-btm: btm_acl_created hci_handle=2 link_role=0 transport=1
07-14 12:24:22.876 25623-25662/? W/bt-l2cap: L2CAP - st: CLOSED evt: 0
07-14 12:24:22.876 25623-25662/? W/bt-l2cap: L2CAP - st: ORIG_W4_SEC_COMP evt: 7
07-14 12:24:23.126 25623-25662/? W/bt-btm: btm_read_remote_version_complete: BDA: b0-10-41-92-8d-1e
07-14 12:24:23.126 25623-25662/? W/bt-btm: btm_read_remote_version_complete lmp_version 7 manufacturer 69 lmp_subversion 1
07-14 12:24:23.249 25623-25662/? W/bt-btm: btm_process_remote_ext_features_page 0: BDA: b0-10-41-92-8d-1e
07-14 12:24:23.249 25623-25662/? W/bt-btm: ext_features_complt page_num:1 f[0]:x03, sm4:11, pend:0
07-14 12:24:23.250 25623-25662/? W/bt-btm: btm_process_remote_ext_features_page 1: BDA: b0-10-41-92-8d-1e
07-14 12:24:23.250 25623-25662/? W/bt-btif: info:x10
07-14 12:24:23.250 25623-25662/? W/bt-l2cap: L2CA_SetDesireRole() new:x0, disallow_switch:0
[ 07-14 12:24:23.250 25623:25648 D/ ]
remote version info [b0:10:41:92:8d:1e]: 7, 45, 1
07-14 12:24:23.267 781-930/? D/BluetoothManagerService: Message: 20
07-14 12:24:23.267 781-930/? D/BluetoothManagerService: Added callback: android.bluetooth.IBluetoothManagerCallback$Stub$Proxy@26f776c3:true
07-14 12:24:23.438 25623-25662/? W/bt-l2cap: L2CAP - st: W4_L2CAP_CON_RSP evt: 19
07-14 12:24:23.493 25623-25662/? W/bt-l2cap: L2CAP - st: W4_L2CAP_CON_RSP evt: 11
07-14 12:24:23.493 25623-25662/? W/bt-l2cap: L2CAP - st: CONFIG evt: 24
07-14 12:24:23.494 25623-25662/? W/bt-l2cap: L2CAP - st: CONFIG evt: 14
07-14 12:24:23.494 25623-25662/? W/bt-l2cap: L2CAP - st: CONFIG evt: 25
07-14 12:24:23.494 25623-25662/? W/bt-l2cap: L2CAP-Upper layer Config_Rsp,Local CID: 0x0041,Remote CID: 0x0040,PSM: 1,our MTU present:1,our MTU:672
07-14 12:24:23.499 25623-25662/? W/bt-l2cap: L2CAP - st: CONFIG evt: 15
07-14 12:24:23.499 25623-25662/? W/bt-l2cap: L2CAP-peer_Config_Rsp,Local CID: 0x0041,Remote CID: 0x0040,PSM: 1,peer MTU present: 0,peer MTU: 672
07-14 12:24:23.554 25623-25662/? W/bt-sdp: process_service_search_attr_rsp
07-14 12:24:23.554 25623-25662/? W/bt-l2cap: L2CA_DisconnectReq() CID: 0x0041
07-14 12:24:23.559 25623-25662/? W/bt-l2cap: L2CAP - st: W4_L2CAP_DISC_RSP evt: 18
07-14 12:24:23.559 25623-25662/? E/bt-btif: DISCOVERY_COMP_EVT slot id:7, failed to find channle, status:1, scn:0
07-14 12:24:23.560 25623-25711/? W/bt-btif: invalid rfc slot id: 7
07-14 12:24:23.560 25368-25368/vertex2016.mvjce.edu.bluealert I/Choreographer: Skipped 105 frames! The application may be doing too much work on its main thread.
07-14 12:24:24.974 295-1069/? D/audio_hw_primary: out_standby: enter: stream (0xab02e8e8) usecase(1: low-latency-playback)
07-14 12:24:25.075 295-1069/? D/hardware_info: hw_info_append_hw_type : device_name = speaker
07-14 12:24:26.834 2506-2608/? I/GCoreUlr: Starting BLE scan: mode: 2
07-14 12:24:26.884 25623-25662/? E/bt-btm: btm_sec_disconnected - Clearing Pending flag
07-14 12:24:26.884 25623-25662/? W/bt-l2cap: L2CA_SetDesireRole() new:x0, disallow_switch:0
07-14 12:24:26.887 25623-25623/? D/BluetoothMapService: onReceive
07-14 12:24:26.887 25623-25623/? D/BluetoothMapService: onReceive, action android.bluetooth.device.action.ACL_DISCONNECTED
07-14 12:24:26.893 2506-26096/? D/BluetoothAdapter: startLeScan(): null