小编Nee*_*eko的帖子

PHP递归多维循环

$printArr = recursive($newArray); //calls recursive function
$data = [];
var_dump($data);
var_dump($printArr);
    function recursive($array, $level = 0)
    {
        $searchingValue = 'tableName';
        foreach($array as $key => $value)
        {
                //If $value is an array.
                if(is_array($value))
                {
                    recursive($value, $level + 1);
                } 
                else
                {
                    //It is not an array, so print it out.
                    if($key == $searchingValue)
                    {
                        echo "[".$key . "] => " . $value, '<br>';
                        $data[] = $value;
                    }
                }
        }
    }
Run Code Online (Sandbox Code Playgroud)

所以我有这个功能,我试图将$ value值保存到$ data []数组中.但它总是将它返回为空,我不知道为什么我不能在函数外部保存$ value.如果我回显$ value我得到了我需要的东西,但就像我提到的那样,变量在这种情况下不会被保存 - 表名.

php arrays recursion loops multidimensional-array

5
推荐指数
1
解决办法
113
查看次数

Laravel 多对多关系与自定义表名和 ID

您好,我在问题 [表名:tblquestion,id:que_id ] 和 Agecategory [表名:tblagecategory,id:aca_id ]之间有很多关系。他们共享名为 QuestionAgecategory [表名:tblquestionagecategory,id:qac_id ] 的表。

我要注意的是,所有 IDS 和表名都是自定义命名的,而不是根据典型的 Laravel 语法。

我试图在 Laravel 中将它们联系起来。到目前为止,当我尝试查看 $question->agecategories 时它返回 null;

$question->agecategories; => 空

但它有记录并在 $question = App\Question::find(1); 之后返回它。

$question = App\Question::find(1); => App\Question {#2901 que_id: 1, que_name: "hello",

问题模型

class Question extends Model
{
    protected $table = 'tblquestion';
    protected $primaryKey = 'que_id';
    protected $keyType = 'integer'; 
    public $incrementing = true;
    public $timestamps = false;

    public function agecategories() 
    {
        return …
Run Code Online (Sandbox Code Playgroud)

migration entity-relationship many-to-many laravel

5
推荐指数
1
解决办法
9214
查看次数

蜂窝状DIV布局

我正在尝试制作一个特定的布局,但我正在努力使用网格CSS。我使用 Flex 或任何其他方法打开。

.container {
display: grid;
grid-template-columns: repeat(auto-fit, 50px);
grid-template-rows: repeat(auto-fit, minmax(80px, 80px));
width: auto;
justify-content: center;
grid-auto-rows: 80px;
margin-bottom: 30px;
width: 322px;
height: auto;
}

.container  > * {
-webkit-clip-path: polygon(50% 0, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%);
clip-path: polygon(50% 0, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%);
}

.block {
position: relative;
height: 100px;
background-color: #fff2aa;
grid-column: 2 span;
display: flex;
align-items: center;
justify-content: center;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
    <div class="block"></div> …
Run Code Online (Sandbox Code Playgroud)

html css grid

3
推荐指数
1
解决办法
301
查看次数