php 每日更改随机报价
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 每日更改随机报价相关的知识,希望对你有一定的参考价值。
<span style="color: #000000; font-weight: bold;">function</span> RandomQuoteByInterval<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$TimeBase</span>, <span style="color: #0000ff;">$QuotesArray</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span>
<span style="color: #808080; font-style: italic;">// Make sure it is a integer</span>
<span style="color: #0000ff;">$TimeBase</span> = <a href="http://www.php.net/intval"><span style="color: #000066;">intval</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$TimeBase</span><span style="color: #66cc66;">)</span>;
<span style="color: #808080; font-style: italic;">// How many items are in the array?</span>
<span style="color: #0000ff;">$ItemCount</span> = <a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$QuotesArray</span><span style="color: #66cc66;">)</span>;
<span style="color: #808080; font-style: italic;">// By using the modulus operator we get a pseudo</span>
<span style="color: #808080; font-style: italic;">// random index position that is between zero and the</span>
<span style="color: #808080; font-style: italic;">// maximal value (ItemCount)</span>
<span style="color: #0000ff;">$RandomIndexPos</span> = <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$TimeBase</span> % <span style="color: #0000ff;">$ItemCount</span><span style="color: #66cc66;">)</span>;
<span style="color: #808080; font-style: italic;">// Now return the random array element</span>
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$QuotesArray</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$RandomIndexPos</span><span style="color: #66cc66;">]</span>;
<span style="color: #66cc66;">}</span>
<span style="color: #808080; font-style: italic;">/*
** --> See the example section below for a
** detailed instruction.
*/</span>
以上是关于php 每日更改随机报价的主要内容,如果未能解决你的问题,请参考以下文章