使用语言文件搜索和替换多维数组

时间:2016-10-01 08:54:27

标签: php arrays codeigniter

我有一个看起来像这样的语言文件

$lang['dashboard ']='Dashboard';
$lang['financial_dashboard']='Financial Dashboard';
$lang['project_dashboard']='Project Dashboard';

数据库中的数组结果

Array ( [0] => Array ( [id] => 109 [text] => dashboard [items] => Array ( [0] => Array ( [id] => 1 [text] => financial_dashboard [items] => 109 ) [1] => Array ( [id] => 108 [text] => project_dashboard [items] => 109 ) ) )

如何使用我的语言文件中的值查找和替换数组中的值,但保持数组不变,以便我的最终输出看起来像这样

Array ( [0] => Array ( [id] => 109 [text] => Dashboard [items] => Array ( [0] => Array ( [id] => 1 [text] => Financial Dashboard [items] => 109 ) [1] => Array ( [id] => 108 [text] => Project Dashboard [items] => 109 ) ) )

任何建议

1 个答案:

答案 0 :(得分:2)

您可以简单地遍历数组并使用in_array()检查替换文本是否可用。如果找到,请将其替换为相应的$ lang值。

a:= make([][]uint8, dy)       // initialize a slice of dy slices
for i:=0;i<dy;i++ {
    a[i] = make([]uint8, dx)  // initialize a slice of dx unit8 in each of dy slices
}