作者aleck945 (总是不知所措)
看板PHP
标题Re: [请益] 请问 array 可以用读档的方式吗
时间Thu Jul 10 18:20:31 2008
※ 引述《dspswen (阿天)》之铭言:
: 我在看一个系统他的翻译是分很多 .inc 档
: .inc 里面内容大概是
: "apple"=>"苹果",
: "banana"=>"香焦",
: "orange",(还没翻)
: 这样日後要维护翻档就直接改 .inc 档就好了
: 不论是要用手动还是用程式写进去
: 那请问这样的 .inc 档要怎麽读进阵列里
: $aaa=file_get_contents("xxx.inc");
: $array=array($aaa);
: 好像怪怪的
: print_r全部都变成[0]=>"所有.inc档的内容都变[0]了"
: 请问这要怎麽代入
: 还有像 "orange" 这样还没翻的,还是要加 => 才行?
: 不然会被补上数字 (譬如 [0]=>"orange") 可是看他档案好像又没有加
: 这是怎麽做的 @@ 谢谢
像这种例子, 通常我都是用以下 key/value 的方式.
xxxx.inc
<?php
$fruits = array (
"apple" => "苹果",
"banana" => "香焦",
"orange" => ""
);
?>
index.php
<?php
include("xxxx.inc");
foreach ($fruits as $key => $val) {
echo $key." = ".$val."<br>";
}
?>
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 122.116.190.50
※ 编辑: aleck945 来自: 122.116.190.50 (07/10 18:21)
1F:推 dspswen :谢谢 我原本也是想这样 07/10 19:17
2F:推 HuangJC :一直不懂干麻要自己填,一个 require 不是就含入了? 07/11 00:46