这是一个简化的例子。尝试生成在每次迭代中都会改变的字符串变量的句子。例如:/*stringText.php<?php$sentences = ["Hello there, $name.","Your gender is $gender","Are you $age years old?",]?>*/$attributes = [ ['name'=>'anna','age'=>14, 'gender'=>'female'], ['name'=>'frank','age'=>16, 'gender'=>'male'], ['name'=>'dan','age'=>15, 'gender'=>'male'], ['name'=>'lara','age'=>16, 'gender'=>'female'],];foreach($attributes as $val){ $name = $val['name']; $age = $val['age']; $gender = $val['gender']; include('stringText.php'); echo $sentences[rand(0,2)].'<br/>';}有没有办法做到这一点而不必每次都调用“包含”?也许将 include 的值存储在变量或类似的东西中?
2 回答
- 2 回答
- 0 关注
- 126 浏览
添加回答
举报
0/150
提交
取消