TomVista
V2EX  ›  问与答

PHP 变量作用域问题

  •  
  •   TomVista · Sep 13, 2021 · 719 views
    This topic created in 1713 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   ·   Solana   ·   2862 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 466ea39e · 40ms · UTC 04:40 · PVG 12:40 · LAX 21:40 · JFK 00:40
    ♥ Do have faith in what you're doing.