假設我們有一個 C 結構
typedef struct _Z3_ast *Z3_ast;
我們想要建立一個陣列
Z3_ast args[2];
並賦值
args[1] = x;
args[1] = y;
在 PHP FFI 中的等效程式碼如下
<?php
$ffi = FFI::cdef(...
// 建立 Z3_ast[2] 型態
$arg_type = FFI::arrayType($ffi->type('Z3_ast'), [2]);
// 建立 Z3_ast[2] 型態的陣列
$args = FFI::new($arg_type);
// 填入陣列
$args[0] = $x;
$args[1] = $y;
?>