我有一个简单的数组.目标是通过密钥对它们进行排序.
$someUnsortedArray = array("140/142" => "FirstValue", "118/120" => "SecondValue", "122/124" => "ThirdValue", "40/42" => "FourthValue");
ksort($someUnsortedArray);
Run Code Online (Sandbox Code Playgroud)
我的输出:
array (size=4)
'118/120' => string 'SecondValue'
'122/124' => string 'ThirdValue'
'140/142' => string 'FirstValue'
'40/42' => string 'FourthValue'
Run Code Online (Sandbox Code Playgroud)
预期产出:
array (size=4)
'40/42' => string 'FourthValue'
'118/120' => string 'SecondValue'
'122/124' => string 'ThirdValue'
'140/142' => string 'FirstValue'
Run Code Online (Sandbox Code Playgroud)
我正在搜索的php中的功能是什么?
假设我有一个如下的 XML -
$xml = '<?xml version="1.0"?>
<step number="9">
<s_name>test</s_name>
<b_sel>12345</b_sel>
<b_ind>7</b_ind>
</step>';
Run Code Online (Sandbox Code Playgroud)
我希望将其转换为对象,但是当我执行以下步骤时,它给了我如下的 stdclass 对象 [我将它分配给 $stepInformation 变量] -
$xml = json_decode(json_encode((array) simplexml_load_string($xml)), 1);
$stepInformation = stdClass Object
(
[@attributes] => Array
(
[number] => 9
)
[s_name] => test
[b_sel] => 12345
[b_ind] => 7
)
Run Code Online (Sandbox Code Playgroud)
所以当我在 php 函数中解析这个 stdclass 对象时
function convertStepInformationToArray($stepInformation)
{
$dom = new DOMDocument();
$stepInfo = "{$stepInformation->s_name}{$stepInformation->b_sel}{$stepInformation->b_ind}";
$dom->loadXML("<document>" . $stepInfo . "</document>");
$domx = new DOMXPath($dom);
$entries = $domx->evaluate("//step");
return $entries;
}
Run Code Online (Sandbox Code Playgroud)
我得到的输出是
DOMNodeList …Run Code Online (Sandbox Code Playgroud) 我在转换这个日期时遇到了麻烦.我想要的是将yyyy-mm-dd格式化的日期转换为月日.我怎样才能做到这一点?下面是我的代码.
$news = mysql_query("SELECT * FROM tblupcomingevents WHERE date >= CURRENT_DATE() LIMIT 5") or die(mysql_error());
while($row = mysql_fetch_array($news))
{?>
<?php echo $row ["date"] ?>
<?php echo $row ["place"] ?>
<?php
}
?>
Run Code Online (Sandbox Code Playgroud) 我正在进行分页功能,但它给了我一个undefined variable error.有人可以帮帮我吗?
我的控制器:
class Home extends CI_Controller
{
function __construct()
{
// Call the Controller constructor
parent::__construct();
$this->load->library('form_validation');
$this->load->library("pagination");
$this->load->model('place');
$this->load->model('place_model');
$this->load->helper('url');
session_start();
}
function manage()
{
$this->load->model('Place_model');
$per_page = 5;
$total = $this->Place_model->count_posts();
$base_url = site_url('home/search');
$config['base_url'] = $base_url;
$config['total_rows'] = $total;
$config['per_page'] = $per_page;
$config['uri_segment'] = '3';
$data['posts'] = $this->Place_model->get_posts($per_page, $this->uri->segment(3));
$this->pagination->initialize($config);
$this->load->view('search_result_page', $data);
}
}
Run Code Online (Sandbox Code Playgroud)
我的模型是place_model:
class Place_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->model('Place');
$this->load->database();
}
function get_posts($limit = NULL, …Run Code Online (Sandbox Code Playgroud) 我试图指向src一个图像文件夹,但努力使语法正确.
get_stylesheet_directory() 是一个wordpress特定的PHP功能,它基本上说指向主题文件夹.
我发布的不是这个网站的wordpress特定区域,因为它纯粹是我遇到的语法问题.
if ($twitter) {
echo "<a href='$twitter' target='_blank'><img src= " get_stylesheet_directory(). '/images'" height='38' width='37' alt='Twitter'>";
}
Run Code Online (Sandbox Code Playgroud)
请问有什么想法吗?
php ×5
arrays ×1
codeigniter ×1
domdocument ×1
mysql ×1
pagination ×1
simplexml ×1
sorting ×1
syntax ×1
xml ×1