我使用 foreach 循环来获取数据,然后使用该数据从数据库中获取信息。
但是当使用 $main[0]->group_number
(文本而不是整数)时,它会返回错误的数据,例如 015 == 01
Product::Budget($budget_id)->Active(1)->Parent($main[0]->group_number)->get();
但是当我将 $main[0]->group_number 放入 $string 中时,它会返回正确的数据。
$value = $main[0]->group_number;
Product::Budget($budget_id)->Active(1)->Parent($value)->get();
现在它返回正确的数据,01==01 和 015==015
为什么第一个返回错误数据而第二个返回正确数据?
// This takes data from another table and puts it into $main
@foreach($groups->insideGroup($budget_id, $group->number, null, 2) as $main)
// This takes data from the last table and puts it into $job, but if using $main value in the Parent() scope, it returns wrong values. Except when putting the value into $string
@foreach(Job::Budget($budget_id)->Active(1)->Parent($main[0]->group_number)->get() as $job)
@endforeach
@endforeach
最佳答案
我相信这是 PHP 的类型杂耍在起作用。 您可以使用以下方法进行测试:
var_dump(015);
var_dump('015');
PHP 将第一个数字视为八进制数
http://www.php.net/manual/en/language.types.integer.php
关于php - 无法在 mysql 中使用 foreach 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21181318/