如何编写函数的工具 [英] How to write a implement of function

查看:61
本文介绍了如何编写函数的工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <?php  
class FileOwners
{
公共静态函数groupByOwners($ files)
{
return NULL;
}
}

$ files = array

Input.txt => Randy
Code.py => Stan
Output.txt => 兰迪
);
var_dump(FileOwners :: groupByOwners($ files));





实施 groupByOwners 函数:

1.接受一个包含每个文件名的文件所有者名称的关联数组。

2.返回包含数组的关联数组每个所有者名称的文件名,按任何顺序排列。



我尝试过:



Quote:

例如我认为,对于关联数组[Input.txt=> Randy,Code.py=> Stan,Output.txt=> Randy] groupByOwners函数应该返回[Randy=> [Input.txt,Output.txt],Stan=> [Code.py]]。

解决方案

文件)
{
return NULL;
}
}


files = array

Input.txt => Randy
Code.py => Stan
< span class =code-string> Output.txt => Randy
);
var_dump(FileOwners :: groupByOwners(


files));





< b>实现一个 groupByOwners 函数:

1.接受一个包含每个文件名的文件所有者名称的关联数组。

2.以任何顺序返回一个包含每个所有者名称的文件名数组的关联数组。



我尝试过:



Quote:

例如我认为,对于关联数组[输入.txt=> Randy,Code.py=> Stan,Output.txt=> Randy] groupByOwners函数应该返回[Randy=> [Input.txt,Output.txt],Stan=> [ Code.py]]。


<?php
class FileOwners
{
    public static function groupByOwners($files)
    {
        return NULL;
    }
}

$files = array
(
    "Input.txt" => "Randy",
    "Code.py" => "Stan",
    "Output.txt" => "Randy"
);
var_dump(FileOwners::groupByOwners($files));



Implement a groupByOwners function that:
1.Accepts an associative array containing the file owner name for each file name.
2.Returns an associative array containing an array of file names for each owner name, in any order.

What I have tried:

Quote:

For example that I thought, for associative array ["Input.txt" => "Randy", "Code.py" => "Stan", "Output.txt" => "Randy"] the groupByOwners function should return ["Randy" => ["Input.txt", "Output.txt"], "Stan" => ["Code.py"]].

解决方案

files) { return NULL; } }


files = array ( "Input.txt" => "Randy", "Code.py" => "Stan", "Output.txt" => "Randy" ); var_dump(FileOwners::groupByOwners(


files));



Implement a groupByOwners function that:
1.Accepts an associative array containing the file owner name for each file name.
2.Returns an associative array containing an array of file names for each owner name, in any order.

What I have tried:

Quote:

For example that I thought, for associative array ["Input.txt" => "Randy", "Code.py" => "Stan", "Output.txt" => "Randy"] the groupByOwners function should return ["Randy" => ["Input.txt", "Output.txt"], "Stan" => ["Code.py"]].


这篇关于如何编写函数的工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆