以下是一个简单的PHP实例,展示了如何编写一个函数来返回调用该函数的用户信息。

```php

实例php返回自己,PHP实例:返回自己的信息  第1张

function returnUserInfo($username) {

// 假设我们有一个用户信息数组,这里用静态变量模拟数据库

static $userInfo = [

'john_doe' => ['name' => 'John Doe', 'email' => 'john@example.com'],

'jane_doe' => ['name' => 'Jane Doe', 'email' => 'jane@example.com']

];

// 检查用户名是否存在

if (isset($userInfo[$username])) {

// 返回用户信息

return $userInfo[$username];

} else {

// 如果用户名不存在,返回空数组

return [];

}

}

// 使用函数并打印结果

$userInfo = returnUserInfo('john_doe');

echo "