的結果,最好的辦法,我有一個multidimentionla陣列什麼是顯示這個數組
array(
"Airportbus"=>array(
"NO"=>array(
"from"=>"Barcelona",
"to"=>"Gerona"
)
),
"flight"=>array(
"SK455"=>array(
"from"=>"Gerona",
"to"=>"Stockholm",
"seat"=>"3A"
),
"SK22"=>array(
"from"=>"Stockholm",
"to"=>"New york",
"gate"=>"Gate 22",
"description"=>"Baggage wiil be transfered from your last leg",
"seat"=>"7B"
)
),
"train"=>array(
"78A"=>array(
"from"=>"Madrid",
"to"=>"Barcelona",
"seat"=>"45B"
)
)
);
我要打印這樣的結果。
1. Take train 78A from Madrid to Barcelona. Sit in seat 45B.
2. Take the airport bus from Barcelona to Gerona Airport. No seat assignment.
3. From Gerona Airport, take flight SK455 to Stockholm. Gate 45B, seat 3A. Baggage drop at ticket counter 344.
4. From Stockholm, take flight SK22 to New York JFK. Gate 22, seat 7B. Baggage will we automatically transferred from your last leg.
這裏的問題是
1.some陣列具有用不同的密鑰"gate","description"
多個元件。 2.在結果中打印一些額外的文字,「坐」,「拿」。
我試圖用
$message = "";
if(issset($result['key']))
{
$message += " some text ".$result['key']. " some text ",
}
if(issset($result['key2']))
{
$message += " some text ".$result['key2']. " some text ",
}
if(issset($result['key2']))
{
$message += " some text ".$result['key2']. " some text ",
}
我想,如果是低效的,因爲每一次新的數組鍵加我一定要添加更多的代碼打印結果。
有沒有更好的辦法可以做到這樣的情況,請大家幫忙。感謝提前:)
至少從一個循環開始。你的數組與你的輸出不匹配。你怎麼知道訂單是火車 - 公共汽車的班機,列車有公共汽車 - 火車 – 2014-09-25 03:17:03
@Dagon能否請你給我一個簡單的例子:( – 2014-09-25 03:19:11
@Dagon,mm沒有訂單:( – 2014-09-25 03:20:03