English 中文(简体)
PHP Variables in Arrays
原标题:PHP Variables in Arrays
  • 时间:2011-11-18 16:50:16
  •  标签:
  • php
  • arrays

页: 1

$output = array();
$output[ num_items_in_tree ] = 0;
$output[ date_of_most_recent_item ] = $today;
$output[ num_comments_in_tree ] = 0;
$output[ date_of_most_recent_comment ] =   ;
$today = the_date();
print_r( $output );

I would expect the date_of_most_recent_item to have today s date but there is zero output.

Oh,我知之甚少......

最佳回答

仅凭您的两份声明($today):

$today = the_date(); // this statement must be before you use $today
$output = array();
$output[ num_items_in_tree ] = 0;
$output[ date_of_most_recent_item ] = $today;
$output[ num_comments_in_tree ] = 0;
$output[ date_of_most_recent_comment ] =   ;
print_r( $output );
问题回答
$output[ date_of_most_recent_item ] = $today;

此时此刻,$today尚未开始,因此date_of_ IX_recent_item 无价值。

页: 1

您确定<代码> 产出[日期_of_ IX_recent_item ]/code>至$today,$today。 尚未确定。 因此,你只是把它确定为一个单位化的变数-无数值。

您的最佳选择:

$output = array();
$output[ num_items_in_tree ] = 0;
$output[ date_of_most_recent_item ] = the_date();
$output[ num_comments_in_tree ] = 0;
$output[ date_of_most_recent_comment ] =   ;

print_r( $output ); 

尚未涵盖的其他要点:假设<代码>_date(<>>>>/code>,则由Wordpress提出,但还是重复了这一数值。 最后的任择论点需要弄错。

编辑:签名为_date(format,美元前,美元后,美元/代码>。 对我来说,这是很奇怪的,因为 $不实,最后是这样。 因此,为了回馈价值,而不是重复,你需要说:

$today = the_date( "F j, Y", "", "", $echo );

自那以后,这些论点就提出。 如果我设计了这一功能,那么我会永远回来,如果用户想要的话,就让用户回来。 如何撰写<代码><?=_date();?>而不是<?





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...