TomVista
V2EX  ›  问与答

PHP 变量作用域问题

  •  
  •   TomVista · Sep 13, 2021 · 694 views
    This topic created in 1705 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   ·   2892 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:38 · PVG 21:38 · LAX 06:38 · JFK 09:38
    ♥ Do have faith in what you're doing.