我的变量中有以下字符串,这是从我的s3存储桶内容中获取的,我需要在我的函数中将其作为真实数组返回。
如何在Laravel中处理此事?
<?php
return array(
"accepted" => "The :attribute must be accepted.",
"active_url" => "The :attribute is not a valid URL.",
"after" => "The :attribute must be a date after :date.",
"alpha" => "The :attribute may only contain letters.",
"alpha_dash" => "The :attribute may only contain letters, numbers, and dashes.",
"alpha_num" => "The :attribute may only contain letters and numbers.",
"before" => "The :attribute must be a date before :date.",
)
答案 0 :(得分:0)
你试过吗
$array = include('path_to_your_file');
dd($array);
答案 1 :(得分:0)
你有一个有效的关联数组,它是“真实的”。
我认为,你已经创建了一个函数,并且你已经返回了一个数组。
function test(){
return array(
"accepted" => "The :attribute must be accepted.",
"active_url" => "The :attribute is not a valid URL.",
"after" => "The :attribute must be a date after :date.",
"alpha" => "The :attribute may only contain letters.",
"alpha_dash" => "The :attribute may only contain letters, numbers, and dashes.",
"alpha_num" => "The :attribute may only contain letters and numbers.",
"before" => "The :attribute must be a date before :date.",
);
}
$data = test();
echo '<pre>'; print_r($data);
您可以通过
访问特定键echo $data['accepted']; // The :attribute must be accepted.
答案 2 :(得分:0)
在我的问题中,我已经定义了我需要从sting访问我的数组,在我的变量中我有这个刺痛,我使用php eval函数从这个sting返回数组。谢谢所有贡献我自己的人。
gcloud compute instances attach-disk [INSTANCE_NAME] --disk [DISK_NAME]
现在我可以执行字符串了。
答案 3 :(得分:0)
我认为,您应该尝试$arr = [ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' ];
$serializedArr = serialize($arr);
$newArr = unserialize($serializedArr);
print_r($newArr);
和/page
RouteConfig.cs