John Davidson

Translating PHP to Powershell

0 comments
Message:


I'm currently translating a PHP script to Powershell, and I'm stuck at the following part:


$data = array();
foreach($extension_data as $key=>$value){
array_push($data,array("name"=>$key,"value"=>$value));
}

Especially, what would the $key=>$value part look like in PowerShell?


EDIT: here's my solution


    $data = @()
foreach($e in $extension_data.getenumerator()){
$data += @{"name" = $($e.name); "value"=$($e.value)}
}


My Answer:
$data = @()
foreach ($key in $extension_data.Keys) {
$data += @{ "name" = $key; "value" = $extension_data[$key] }
}

Rate this post

3 of 5 based on 5733 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us