I need to hash a value using md5 in a PHP array value,
'password' => array(
'value' => md5($form_data['password'])
)
I tried with the above code but it didn't seem to work.
check this code and working . i think your code is correct . so if you show your full array then we can understand which section problem. i define array as your code array and it is working fine
<?php
$array = array(
'password' => array(
'value' => '12456'
),
'name' => array(
'name' => 'Test Name'
)
);
echo "<pre>";
print_r($array);
$md5_array = array(
'password' => array(
'value' => md5('12456')
),
'name' => array(
'name' => 'Test Name'
)
);
echo "<pre>";
print_r($md5_array);
?>
then output before md5 :
Array
(
[password] => Array
(
[value] => 12456
)
[name] => Array
(
[name] => Test Name
)
)
after md5 :
Array
(
[password] => Array
(
[value] => 6a9edcb7b63821802aa44d35d531c9fc
)
[name] => Array
(
[name] => Test Name
)
)
for more information
http://php.net/manual/en/function.md5.php
Related
I have simple question:
How to change this array
Array ( [0] => taxonomy-term-1 [1] => taxonomy-term-2 [2] => taxonomy-term-3 )
to this array?
array( 'taxonomy-term-1', 'taxonomy-term-2', 'taxonomy-term-3' )
Why I am asking for that:
$slugs = wp_get_post_terms($post->ID,'ml_patternsCustomTaxonomy',['fields'=>'slugs']);
returns
Array ( [0] => taxonomy-term-1 [1] => taxonomy-term-2 [2] => taxonomy-term-3 )
but
array(
'title' => $title,
'content' => trim($patternContent),
'categories' => $slugs
)
doesn't work, and
//
'categories' => array( 'taxonomy-term-1', 'taxonomy-term-2', 'taxonomy-term-3' ),
works.
Why?
i have below array with key combined * i want get the value using array key
i got response from api
Array (
[pos] => Bitpay\Token Object
(
[token:protected] => 8Q13oFMiBLBcqFCK5wWfhUYxxhcpkq4C6Xqh6ipgbxTm
[resource:protected] =>
[facade:protected] => pos
[createdAt:protected] =>
[policies:protected] => Array
(
)
[pairingCode:protected] =>
[pairingExpiration:protected] =>
)
[pos/invoice] => Bitpay\Token Object
(
[token:protected] => 4XyeM78xv6ywzTB3Cc2yak7Bb9duAW1DaCu5XDAVuSEQ
[resource:protected] =>
[facade:protected] => pos/invoice
[createdAt:protected] =>
[policies:protected] => Array
(
)
[pairingCode:protected] =>
[pairingExpiration:protected] =>
)
)
after i convert array i got below array structure, I want get a token:protected value, How can i get this
Array(
[*token] => 8Q13oFMiBLBcqFCK5wWfhUYxxhcpkq4C6Xqh6ipgbxTm
[*resource] =>
[*facade] => pos
[*createdAt] =>
[*policies] => Array
(
)
[*pairingCode] =>
[*pairingExpiration] =>
)
I want take get a token value, Any one Please help.
Using quotes should make it all possible:
<?php
$myArray = array(
'*token' => '8Q13oFMiBLBcqFCK5wWfhUYxxhcpkq4C6Xqh6ipgbxTm',
'*resource' => '',
'*facade' => 'pos',
'*createdAt' => '',
'*policies' => array
(
),
'*pairingCode' => '',
'*pairingExpiration' => '',
);
print $myArray['*token'];
?>
im using yii1 on my application.
i want to convert from cActivedataProvider to array
this is the code
$dataSS = new CActiveDataProvider('category', array(
'criteria' => array(
'condition' => 'menu=:menu',
'params' => array(':menu' => $menu),
),
'pagination' => false
));
$dataMenu = array();
foreach ($dataSS->getData() as $record) {
$dataMenu[] = array(
'label' => $record->name,
'url' => '#',
);
}
this is the result :
Array (
[0] => Array ( [label] => Food and Drink [url] => # )
[1] => Array ( [label] => Sleman [url] => # )
)
the result that i expected :
Array (
Array ( 'label' => 'Food and Drink', 'url' => '#' ) ,
Array ( 'label' => 'Sleman', 'url' => '#' ) ,
)
any suggestion?
Finally get the answer,
this is really my bad because i call the function on wrong way.
This is the wrong way :
'items' =>array(Category::model()->getMenu("2");),
and this is the correct way :
'items' =>Category::model()->getMenu("2"),
I have an array, i want to convert this to json, but it returns null for a field,
here is my array:
[workname] => IŞIKLAR MÜHENDİSLİK
[workno] => 22330
[workdate] => Array
(
[0] => Array
(
[date] =>
[type] => ELEKTRİK
)
[1] => Array
(
[date] => 31.12.2007
[type] => ELEKTRİK
)
)
when i convert this to json, i get workdate element as null.
{"workname":"IŞIKLAR MÜHENDİSLİK","workno":"22330","workdate":null}
$arr = array('workname' => 'IŞIKLAR MÜHENDİSLİK','workno' => 22330,'workdate' => array('0' => array('date' => '','type' => 'ELEKTRİK'),'1' => array('date' => '31.12.2007','type' => 'ELEKTRİK')));
echo json_encode($arr);
outputs
{"workname":"I\u015eIKLAR M\u00dcHEND\u0130SL\u0130K","workno":22330,"workdate":[{"date":"","type":"ELEKTR\u0130K"},{"date":"31.12.2007","type":"ELEKTR\u0130K"}]}
you can check it here http://sandbox.onlinephpfunctions.com/code/68c91d260a0a18d584dab871f56dd7c97482ca04
$arr=array(
'workname' => 'IŞIKLAR MÜHENDİSLİK',
'workno' => 22330,
'workdate' => Array (
Array (
'date' => '',
'type' => 'ELEKTRİK'
),
Array(
'date' => '31.12.2007',
'type' => 'ELEKTRİK'
)
)
);
echo json_encode($arr);
The following question can either be solved by probably changing my use of the find method in Cake PHP OR using some PHP function. I would prefer to solve it using Cake but it doesn't matter too much. I have any array like this:
Array
(
[0] => Array
(
[Model] => Array
(
[id] => 14
[foo] => bar
)
)
[1] => Array
(
[Model] => Array
(
[id] => 15
[foo] => something
)
) .............
I just want to remove the Model index and just use the numeric one. The following function generated this array:
$arr = $this->Model->find('all', array('contain' => false ) );
I probably need to change the 'contain' part of the call. Basically, in addition to the data that appears under each Model index, I also have a second and third model and the contain = false just restricts Cake from getting data from the current model (Model).
If I understand your question correctly, I think CakePHP's Set::combine function will help http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::combine :
$result = Set::combine($your_array, '{n}.Model.id', '{n}.Model.data');
This will result in:
Array
(
[14] => Array
(
[foo] => bar
)
[15] => Array
(
[foo] => something
)
)
you have to write your own piece of code to modify your array , here is a function that will do what you want (you can improve it)
function reformArray($array,$modelName)
{
foreach($arr as $key => $value)
{
$newArr[] = $arr[$key][$modelName];
}
return $newArr;
}
you have to pass your array and the Model Name to this function and will return you the result
$a = array(
array(
'User' => array(
'id' => 2,
'group_id' => 1,
'Data' => array(
'user' => 'mariano.iglesias',
'name' => 'Mariano Iglesias'
)
)
),
array(
'User' => array(
'id' => 14,
'group_id' => 2,
'Data' => array(
'user' => 'phpnut',
'name' => 'Larry E. Masters'
)
)
),
array(
'User' => array(
'id' => 25,
'group_id' => 1,
'Data' => array(
'user' => 'gwoo',
'name' => 'The Gwoo'
)
)
)
);
RUN THIS TO REMOVE THE MODEL NAME USER
Set::extract($a, '{n}.User');
WILL RETURN THIS
$a = array(
array(
'id' => 2,
'group_id' => 1,
'Data' => array(
'user' => 'mariano.iglesias',
'name' => 'Mariano Iglesias'
)
),
array(
'id' => 14,
'group_id' => 2,
'Data' => array(
'user' => 'phpnut',
'name' => 'Larry E. Masters'
)
),
array(
'id' => 25,
'group_id' => 1,
'Data' => array(
'user' => 'gwoo',
'name' => 'The Gwoo'
)
)
);
In CakePHP 2:
$data = $this->Model->find('all');
$data = Set::extract('/Model/.', $data );
You can achieve this result by foreach also
foreach ($data as $k => &$t) {
$t = $t['Model']
}
It will be much easier with Object. Change the Array with Object.
Actually I had faced the same problem with nested array And I found the solution with Set::map($array);
If you don't want the model_name as nested array, You can prefer this solution.
$data = array(
array(
"IndexedPage" => array(
"id" => 1,
"url" => 'http://blah.com/',
'hash' => '68a9f053b19526d08e36c6a9ad150737933816a5',
'get_vars' => '',
'redirect' => '',
'created' => "1195055503",
'updated' => "1195055503",
)
),
array(
"IndexedPage" => array(
"id" => 2,
"url" => 'http://blah.com/',
'hash' => '68a9f053b19526d08e36c6a9ad150737933816a5',
'get_vars' => '',
'redirect' => '',
'created' => "1195055503",
'updated' => "1195055503",
),
)
);
$mapped = Set::map($data);
/* $mapped now looks like: */
Array
(
[0] => stdClass Object
(
[_name_] => IndexedPage
[id] => 1
[url] => http://blah.com/
[hash] => 68a9f053b19526d08e36c6a9ad150737933816a5
[get_vars] =>
[redirect] =>
[created] => 1195055503
[updated] => 1195055503
)
[1] => stdClass Object
(
[_name_] => IndexedPage
[id] => 2
[url] => http://blah.com/
[hash] => 68a9f053b19526d08e36c6a9ad150737933816a5
[get_vars] =>
[redirect] =>
[created] => 1195055503
[updated] => 1195055503
)
)
you may do this :
$tmp = $this->Model->find('all', array('contain' => false ) );
$arr = $tmp['ModelName'];