php - 无法在 mysql 中使用 foreach 值

标签 php mysql laravel-4

我使用 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/

相关文章:

php - 在home_v.php页面点击Add student按钮,打开另一个查看页面user_v.php

mysql - 为什么我的程序不起作用?

php - 使用 artisan 迁移 Laravel 数据库

laravel - 使用 $collection->filter() 过滤 Eloquent 集合数据

laravel - 插入忽略 Laravel 4

php - 预期的内容类型 text/json 得到 text/html

php - 添加多个 MySQL 条目

php - 解析使用 GD 库创建的临时文件图像对象以解析 mPDF 中的 GIF 图像时出错

mysql - 忘记临时mysql密码

php - 一个查询中的多个数学值