我想从php中的数组输出一个特定的值
下面是我的代码和数组 $content
<?php
$content = $_POST;
for($i=1; $i < $content['itemCount'] + 1; $i++) {
$name = 'item_name_'.$i;
$quantity = 'item_quantity_'.$i;
$price = 'item_price_'.$i;
$image='item_image_'.$i;
$option='item_options_'.$i;
$total = $content[$quantity]*$content[$price];
}
?>
<?php
print_r( $content );
?>
Run Code Online (Sandbox Code Playgroud)
输出显示如下:
Array ( [currency] => INR
[shipping] => 0
[tax] => 0
[taxRate] => 0
[itemCount] => 3
[item_name_1] => Our Nest
[item_quantity_1] => 1
[item_price_1] => 1900
[item_options_1] => image: CF01108.jpg, productcode: 602793420
[item_name_2] => Our Nest
[item_quantity_2] => 1
[item_price_2] => 2100 …Run Code Online (Sandbox Code Playgroud) 我正在Do While loop我的项目中工作,第一次工作正常.
之前while statement,我为一个数组赋值,我能够在代码底部成功打印数组,但是当我在循环顶部检查时它变为0.
码:
$looparray = array();
$loopend = 0;
$arraymer = array();
$poolafirtsid = $previous_array_values; //previous array values
do {
if (sizeof($looparray) == 0) {
$firstsponarray = $poolafirtsid;
} else {
$firstsponarray = $looparray;
}
$firstsponarray = getUserArray($poolafirtsid);
//get user arraylist of first
foreach ($firstsponarray as $avalue) {
$rooparray = membercount($avalue);
$bsponarray = getUserArray($avalue);
//get second users arraylist 9
if (sizeof($bsponarray > 0)) …Run Code Online (Sandbox Code Playgroud) 我想使用PHP将值存储到会话中
例如,$id=10我想将此值存储在会话中
我试过了
$pid= session_id($id);
echo $pid;
Run Code Online (Sandbox Code Playgroud)
和
$pid = $_SESSION['$id'];
Run Code Online (Sandbox Code Playgroud)
但没有工作
我想使用经度和纬度在TextView中获取城市。我越来越IndexOutOfBoundsException。
AndroidGPSTrackingActivity.java
import android.app.Activity;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import static com.example.khaledsb.location.R.id.lng;
import static java.util.Locale.*;
public class AndroidGPSTrackingActivity extends Activity {
public static float distFrom(float lat1, float lng1, float lat2, float lng2) {
double earthRadius = 6371000; //meters
double dLat = Math.toRadians(lat2-lat1);
double dLng = Math.toRadians(lng2-lng1);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
Math.sin(dLng/2) * Math.sin(dLng/2);
double c = …Run Code Online (Sandbox Code Playgroud) android google-maps reverse-geocoding indexoutofboundsexception
我正在尝试从Google地点选择器中获取城市名称。有什么方法可以使用地点选择器API获取城市名称。我知道我们不能简单地通过place.getCity();以下代码从API获取它。
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == REQUEST_PLACE_PICKER){
if(resultCode==RESULT_OK){
Place place = PlacePicker.getPlace(data,this);
final CharSequence name = place.getName();
final CharSequence address = place.getAddress();
final CharSequence phone = place.getPhoneNumber();
final String placeId = place.getId();
final LatLng latLng = place.getLatLng();
if(place.getLocale() != null) {
String aname = place.getLocale().toString();
areaname.setText(aname);
}
location.setText(address);
gname.setText(name);
latlon.setText(String.valueOf(latLng));
}
}
}
Run Code Online (Sandbox Code Playgroud)
我不希望城市中有任何空值。我读了Geocoder大部分将提供空值。
我正在尝试从Google反向地理编码API获取城市名称,我的代码显示的是该位置的完整地址,但我只需要城市。波纹管是我的代码
<?php
session_start();
if(!empty($_POST['latitude']) && !empty($_POST['longitude'])){
//Send request and receive json data by latitude and longitude
$url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.trim($_POST['latitude']).','.trim($_POST['longitude']).'&sensor=false';
$json = @file_get_contents($url);
$data = json_decode($json);
$status = $data->status;
if($status=="OK"){
//Get address from json data
//$location = $data->results[0]->formatted_address;
$location = $data->results[0]->address_components;
}else{
$location = '';
}
//Print city
$_SESSION['getgeoloc']=$location[6]->long_name;
echo $location;
}
?>
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下代码显示城市,但有时会显示邮政编码,有时还会显示城市名称
$_SESSION['getgeoloc']=$location[6]->long_name;
Run Code Online (Sandbox Code Playgroud)
有什么最好的办法吗?