TomVista
V2EX  ›  问与答

PHP 变量作用域问题

  •  
  •   TomVista · Sep 13, 2021 · 960 views
    This topic created in 1860 days ago, the information mentioned may be changed or developed.

    比较简单,我实在是在文档里找不到,被 PHP 逼疯的第一周

    怎样正常访问顶层的 $video $displayId

    <?php
    $video =[]
    $displayId =[]
    function videoRender(){
      global $video // error
      $video // false
    }
    
    array_filter($video,function($index,$item){
    
    foreach($video as $videoItem){
    
    if($item == $videoItem->id){
    return false;
    }
    }
    
    return true;
    
    },1)
    
    ?>
    
    Supplement 1  ·  Sep 14, 2021

    modelVideo 应该全局定义

    global $modelVideo;
    $modelVideo=[]
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   921 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 21:51 · PVG 05:51 · LAX 14:51 · JFK 17:51
    ♥ Do have faith in what you're doing.