我提出一个问题,我似乎无法找到解决办法。 In
foreach( $results->result as $item )
the following code
$item->title = str_replace( " - Home", "", $item->title );
总是犯错误
<>可见的致命错误:> 不能将等级块的物体改装为地块。
我想str_replace
能够处理阵列? 我需要作什么改动才能完成这项工作?
感谢任何建议!
我提出一个问题,我似乎无法找到解决办法。 In
foreach( $results->result as $item )
the following code
$item->title = str_replace( " - Home", "", $item->title );
总是犯错误
<>可见的致命错误:> 不能将等级块的物体改装为地块。
我想str_replace
能够处理阵列? 我需要作什么改动才能完成这项工作?
感谢任何建议!
它不是阵列,而是标的,,正如“<>m>......”的错误所言,你是否得到任何机会的<代码>json_decode(?
然而,解决办法很简单,因为它涉及一系列问题:
$item->title = str_replace( " - Home", "", (array) $item->title );
Another point about this is that if you are wanting to modify the data held in $results->result
, and not just a copy of it, you will need your foreach
to be:
foreach( $results->result as &$item )
......并作为参考而不是复制件......
var_dump($item-> entitled)
,以了解物体所看的情况。
Also, you loop won t do what you expect, after the loop has finished, all objects in $results->result
will still have the same values (use foreach($results->result as &$item)
(pass by reference))
$item->
,因为它是一个阵列,是一个物体。
If you re just looking for a patch, you might be able to get away with casting it. If everything else is working, I would do this because it really has the fewest side-effects:
// convert it to an array before passing it through str_replace
// (array) $item->title
// then convert it back to its original form by casting the result back
// (object) str_replace
$item->title = (object) str_replace( " - Home", "", (array) $item->title );
如果<代码><><>> > > /代码>必须是一阵,你可以不必填写<代码>(目标)代码>,但我认为,在设定<代码><<<>>><<<>>/代码>时,跟踪这一条,其价值是正确的。
BTW——如果你在休息室外重新规划使用<代码>$-> ,你还需要确保你使用提及方式更新项目本身:
foreach($results->result as &$item)
{
$item->title = (object) str_replace( " - Home", "", (array) $item->title );
}
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 ...
<?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 = ...
I found this script online that creates a thumbnail out of a image but the thumbnail image is created with poor quality how can I improve the quality of the image. And is there a better way to create ...
如何确认来自正确来源的数字。
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 ...
I wonder there is a way to post a message to a facebook business page with cURL? thanks
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? 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 ...