我想起了我去过一家公司,让我写冒泡排序,这么简单的排序我分分钟就写完了,结果面试官看了我的代码之后就说我写的不对,我问他哪里不对他又说不出来 https://www.v2ex.com/t/454877
PHP 里如何实现数组转 xml 并且格式化https://www.v2ex.com/t/454894
https://packagist.org/?query=array%20xml https://github.com/spatie/array-to-xml
function arrayConvertXml($arr, $xml = '', $deep = 1) {
if (!is_array($arr)) {
return null;
}
foreach ($arr as $key => $value) {
if (is_array($value)) {
if ($deep > 1) {
$xml .= str_pad('', ($deep - 1) * 2, ' ');
}
$xml .= "<$key>" . PHP_EOL;
$xml = arrayConvertXml($value, $xml, $deep + 1);
if ($deep > 1) {
$xml .= str_pad('', ($deep - 1) * 2, ' ');
}
$xml .= "</$key>" . PHP_EOL;
} else {
$xml .= str_pad('', ($deep - 1) * 2, ' ');
$xml .= "<$key>" . $value . "</$key>" . PHP_EOL;
}
}
return $xml;
}
public function arrayToXML($arr) {
$xml = "<xml>";
foreach ($arr as $key => $val) {
$node = "";
if ( is_string($val) || is_int($val) || is_double($val) || is_float($val) ) {
$val = htmlspecialchars($val);
$node = "<{$key}>{$val}</{$key}>";
} else if (is_array(val)) {
die("不应该有这个参数的");
}
$xml .= $node;
$xml .= "\n";
}
$xml .= "</xml>";
return $xml;
}
private function xmlToArray($xml) {
/*
<xml><return_code><![CDATA[SUCCESS]]></return_code>
<return_msg><![CDATA[OK]]></return_msg>
<appid><![CDATA[wx2949f84b5ee561e9]]></appid>
<mch_id><![CDATA[1502705451]]></mch_id>
<nonce_str><![CDATA[YfEbfNE0xdUjJPAK]]></nonce_str>
<sign><![CDATA[5084033CADE92C9C32798406C3D5C82F]]></sign>
<result_code><![CDATA[SUCCESS]]></result_code>
<prepay_id><![CDATA[wx241217030922516345c975b91289464085]]></prepay_id>
<trade_type><![CDATA[JSAPI]]></trade_type>
</xml>
*/
$ret = array();
$parser = xml_parser_create("UTF-8");
$values = array();
$keys = array();
xml_parse_into_struct($parser, $xml, $values, $keys);
foreach ($keys as $nodeName => $val) {
$id = $val[0];
if (!empty($values[$id]["value"])) {
$nodeName = strtoupper($nodeName);
$ret[$nodeName] = $values[$id]["value"];
}
}
return $ret;
}
/**
* 转换数组为 SimpleXMLElement
*
* 数组键名转换为 nodeName(value为数组时) 或 attributeName(value非array时)
* 数组键名为 _ 时转换为 innerText
*
* 数组值转换为 nodeValue或attribute
* 数组值为数组时转换为子节点
* 数组值为 null 时转换为空节点
*
* todo array.value 非数组时验证是否为标量数据类型
*
* @param array $arr 数据数组
* @param object $xml SimpleXMLElement 实例的引用
* @param string $nodeName 递归中调用参数,调用时不需要提供
* @return void
*/
function arrayToXML(array $arr, \SimpleXMLElement &$xml, $nodeName = '') {
foreach ($arr as $key => $val) {
if (is_array($val)) {
if (is_numeric($key)) {
arrayToXML($val, $xml->addChild($nodeName));
} else {
if (!isset($val[0])) {
arrayToXML($val, $xml->addChild($key));
} else {
arrayToXML($val, $xml, $key);
}
}
} else {
if ($key !== '_') {
if (!is_null($val)) {
$xml->addAttribute($key, (string)$val);
} else {
$xml->addChild($key);
}
} else {
$xml->{0} = $val;
}
}
}
}
// 使用示例
$arr = [
'node' => [
'attribute' => '123',
'subNode' => [
'emptyNode' => null,
'innerTextNode' => [
'_' => 'some text here',
'attribute' => 'attr',
],
],
],
];
$root = 'documentRoot';
$xml = new \SimpleXMLElement("<?xml version='1.0' encoding='UTF-8' ?><{$root}></{$root}>");
arrayToXML($arr, $xml);
$xml = $xml->asXML();
// output
// <?xml version="1.0" encoding="UTF-8"?>
// <documentRoot><node attribute="123"><subNode><emptyNode/><innerTextNode attribute="attr">some text here</innerTextNode></subNode></node></documentRoot>
// http://php.net/manual/en/simplexml.examples-basic.php#example-6636
// 去掉 xml 版本头信息和最后的换行符https://gist.github.com/consatan/b5095c523f6179fb4d1b
// $xml = preg_replace('/\r\n|\r|\n/', '', strstr($xml->asXML(), "<{$root}"));
答得很差但是被录取了,可能:
1、公司人才流失严重
2、HR 冲业绩
3、面试官水平较低
4、应聘者长得好看
答得不错但是没被录取,可能:
1、公司养不起人才
2、面试官妒忌贤能
3、面试官心情不好
4、应聘者长得难看
总之,面试的过程跟结果通常不是面试公司是否录取的直接原因。
大城市机会多,如果你发展了很多年,还是个普通码农,回老家未必是坏事,但是你事业有成,只是觉得累,还是别回去了,因为有些人适合大城市,有些人适合小城市。心态也很重要,我有个同学,在大城市工作,年薪 15 万,在老家买了房,一直想回,成家之后就回不去了,因为小城市根本没法提供年薪 15 万的工作,而且他的妻子也不愿意回去,因为也没有适合的工作,回去能干嘛。
能回老家的三种前提:
1,赚大钱后,荣贵故里;
2,单身,回家创业,在家乡成家立业;
3,赚够钱,发现老家商机,带妻儿回家从事其他行业。
4,靠公务员,进事业单位,提前养老。:)https://www.v2ex.com/t/454476#reply21
Git 分支操作介绍 http://blog.jobbole.com/114107/ git push origin :myBranch 命令删除 myBranch 的远程分支 git push -d origin myBranch
我想起了我去过一家公司,让我写冒泡排序,这么简单的排序我分分钟就写完了,结果面试官看了我的代码之后就说我写的不对,我问他哪里不对他又说不出来 https://www.v2ex.com/t/454877
PHP 里如何实现数组转 xml 并且格式化https://www.v2ex.com/t/454894
https://packagist.org/?query=array%20xml https://github.com/spatie/array-to-xml
答得很差但是被录取了,可能:
1、公司人才流失严重
2、HR 冲业绩
3、面试官水平较低
4、应聘者长得好看
答得不错但是没被录取,可能:
1、公司养不起人才
2、面试官妒忌贤能
3、面试官心情不好
4、应聘者长得难看
总之,面试的过程跟结果通常不是面试公司是否录取的直接原因。
大城市机会多,如果你发展了很多年,还是个普通码农,回老家未必是坏事,但是你事业有成,只是觉得累,还是别回去了,因为有些人适合大城市,有些人适合小城市。心态也很重要,我有个同学,在大城市工作,年薪 15 万,在老家买了房,一直想回,成家之后就回不去了,因为小城市根本没法提供年薪 15 万的工作,而且他的妻子也不愿意回去,因为也没有适合的工作,回去能干嘛。
能回老家的三种前提:
1,赚大钱后,荣贵故里;
2,单身,回家创业,在家乡成家立业;
3,赚够钱,发现老家商机,带妻儿回家从事其他行业。
4,靠公务员,进事业单位,提前养老。:)https://www.v2ex.com/t/454476#reply21
Git 分支操作介绍 http://blog.jobbole.com/114107/ git push origin :myBranch 命令删除 myBranch 的远程分支 git push -d origin myBranch