php8.5
Home/ Manual/ lua / lua/ Lua::assign

Lua::assign

PHP function Edit on GitHub ✎

(PECL lua >=0.9.0)

Assign a PHP variable to Lua

Description

Lua::assign(string $name, string $value): mixed

Func

Parameters

name
value

Return Values

Returns $this or null on failure.

Examples

Lua::assign()example

php
<?php
$lua = new Lua();
$lua->assign("php_var", array(1=>1, 2, 3)); //lua table index begin with 1
$lua->eval(<<<CODE
    print(php_var);
CODE
);
?>

The above example will output:

output
Array
 (
     [1] => 1
     [2] => 2
     [3] => 3
 )

Source: reference/lua/lua/assign.xml · from the official PHP manual (php/doc-en)