在 PHP 中翻译字母表
我是一名学生,对 PHP 感到困惑...... 这是我们的作业:
两个孩子创造了自己的语言。当他们写的时候,真的很难理解。 你的目的是翻译他们的话以理解他们。 当他们写 apricot 时,它想说 dolphin
修改文件 index.php 并声明一个像这样的字符串 « apricot » 和一个包含关联数组的变量。 编写一个返回翻译后的单词并显示该单词的函数。 您必须使用循环和两个函数:implode()
和 explode()
。 !
i'm a student confused about PHP....
this is our homework:
Two children created their own language. And when they write it’s really difficult to understand.
Your purpose is to translate their words to understand them.
When they write apricot it wants to say dolphin
Modify the file index.php and declare a string like this « a.p.r.i.c.o.t » and a variable which contains the associative array.
Write a function which returns the translated word and display the word.
You have to use a loop and both functions: implode()
and explode()
.
!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我假设您有 PHP 语法的基本知识。
implode($glue, $pieces) 是一个函数,它接受一个数组 ($pieces) 并将所有部分组合在一起作为一个字符串。所以:
当输入 implode('', $pieces) 时将返回字符串 'Thisisasentence.'。第一个参数 ($glue) 是单词之间的分隔符,因此我们可以使用空格(例如 implode(' ', $pieces))并得到“这是一个句子”。
explode($delimiter, $string) 的工作方式相反。也就是说它将把字符串变成数组。例如
然后内爆。我不会给你 PHP,因为你应该自己做,但这是伪代码:
I'll assume you have basic knowledge of PHP syntax.
implode($glue, $pieces) is a function that takes an array ($pieces) and puts all the parts together as a string. So:
When fed into implode('', $pieces) will return the string 'Thisisasentence.' The first parameter ($glue) is the separator between the words, so we could use a space (e.g. implode(' ', $pieces)) and get 'This is a sentence.'
explode($delimiter, $string) works in the opposite way. That is it will turn the string into an array. e.g.
Then implode. I won't give you the PHP since your suppose to be doing it yourself, but here's it in pseudocode:
这应该可以做到...
This should do it...
看起来你在谈论 Ceaser 的密码,谷歌一下,我在 Wiki 上看到了一个 Java 示例链接,可以安全地转换为 PHP
It looks like you are talking about Ceaser's cipher, google it, I have seen a Java example link on Wiki which can be safely converted to PHP
您可以从创建一个数组开始:
之后您必须查找一些有关 implode然后爆炸,再有帮助我会考虑作弊..
You can start by making an array:
After that you have to look up some info about implode and explode, anymore help i would consider cheating..
有很多(希望)有用的注释来解释每一行的作用
With lots of (hopefully) helpful comments to explain what each line does